Assign a System.DateTime variable to a System.DateTime[?]

How do I assign a System.DateTime variable to a System.DateTime? variable?
LVL 1
allelopathAsked:
Who is Participating?
 
p_davisCommented:
DateTime t1 = new DateTime();

DateTime? t2 = t1;
//or

t1 = t2.Value
//or
t1 = (DateTime)t2
0
 
p_davisCommented:
just like you would any other datetime
0
 
p_davisCommented:
the other way though you would have to either cast to datetime or use the datetime?'s value property
0
 
allelopathAuthor Commented:
I get this compile error:
Cannot convert source type System.Nullable<System.DateTime> to target type <System.DateTime>
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
System.DateTime? means that it is either a System.DateTime OR a null.  
System.DateTime means it can ONLY be a System.DateTime.

In other words they are they same apart from one being able to have a value null.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.