Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 84.5k

When instantiate a class and when not?

Mar 11 2023 11:29 AM

Hi

I wonder why i can define and use a variable of type DateTime without having to instantiate class DateTime (DateTime dat = new DateTime while with random, i have to use Random rnd = new Random(); otherwise, i get the error "unassigned local variable": 

Thanks.

DateTime dat;
dat = DateTime.Parse("12/02/12");
 Console.WriteLine(dat.ToLongDateString()); // this works without DateTime dat = new DateTime: why?

 

Random rnd;
Console.Write(rnd.Next(2)); error "unassigned local variable"


Answers (1)