Home > Software design >  how can i get only month number and year randomly without time in c#
how can i get only month number and year randomly without time in c#

Time:02-17

How can I generate a random date that only has the number of the month and the year in a random way that comes in this EXAMPLE format "05/23" in c #?

CodePudding user response:

Random rnd = new Random();

int month = rnd.Next(1,12);
int year = rnd.Next(2000,2050);

string date = $"{month:D2}/{year:D2}";
  • Related