Link to home
Start Free TrialLog in
Avatar of deleyd
deleydFlag for United States of America

asked on

make a copy of a DateTime variable

Can I do this to make a copy of a DateTime variable, or does my resulting variable MyDT just point to dt which then disappears?
DateTime MyDT;

private void myfunc()
{
  DateTime dt = DateTime.Now;
  MyDT = dt;
}

Open in new window

I recall if you want to make a copy of a class instance you have to copy all the internals of the class instance, you can't just say myclasscopy = myclass.

Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

DateTime is a structure, not an object. I.e.it is value type.
Therefore you can do that.
ASKER CERTIFIED SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial