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
2010-10-22 02:48:50
That looks simple enough. Using the new keyword isn't going to cause going to cause problems?
Sinaesthetic
2010-10-22 02:50:31
No remember dateTimes its an array of DateTime Objects so inside it must be instance of DateTime class.
Necronet
2010-10-22 02:59:17
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
2010-10-22 03:02:04
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
2010-10-22 03:17:57