views:

38

answers:

1

Hey guys, im a bit lost on how to do this. I know how to initialize an array with values at the time of declaration, but how would i do it with a DateTime type array since it takes multiple arguments to create a date??

+4  A: 

You mean like this?

DateTime[] dateTimes = new DateTime[]
{
    new DateTime(2010, 10, 1),
    new DateTime(2010, 10, 2),
    // etc
};
Phil Brown
That looks simple enough. Using the new keyword isn't going to cause going to cause problems?
Sinaesthetic
No remember dateTimes its an array of DateTime Objects so inside it must be instance of DateTime class.
Necronet
ok, i did try it without the new keyword. Seems to work fine with just { DateTime(x,x,x) } etc. I was just worried that the new keyword would be creating new objects for each value, which I didn't need. Thanks!
Sinaesthetic
I'm confused. If you want an array of DateTime objects, then each item in the array should be a new (or existing) DateTime object.
Phil Brown