Hello everyone,
Since DateTime is struct other than class, each time when we use DateTime abc = DateTime.Now, there are two copies of DateTime structs?
1.
One instance is created by DateTime struct internally, which represents the current time, and another instance is copied from the internal instance to the value type variable abc when we perform assignment operation?
2.
I think the internal instance is a waste? Since it is useless when the value is copied to variable abc?
thanks in advance,
George
George GeorgePosted Jun 10, 2008, 2:56 AM
Thanks Neetika Gupta,
I agree with you. But my original question is about DateTime.Now specically, not about any time. I think you agree with my points that two instances are created? :-)
regards,
George
Neetika GuptaPosted Jun 10, 2008, 2:41 AM
We can call constructor of DateTime if a particular date is to be assigned:
DateTime abc = new DateTime(2008, 6, 10) //Date is 10 Jun, 2008(midnight)
George GeorgePosted Jun 10, 2008, 12:52 AM
Thanks Neetika Gupta,
So, you agree with me that two instances are created in statement DateTime abc = DateTime.Now?
regards,
George
Neetika GuptaPosted Jun 10, 2008, 12:45 AM
Well I think that after the internal instance is copied to the value type variable abc, the internal instance gets disposed off implicitly.