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

Posted on 2013-01-25
Last Modified: 2013-01-25
How do I assign a System.DateTime variable to a System.DateTime? variable?
Question by:allelopath
  • 3
LVL 22

Expert Comment

ID: 38819330
just like you would any other datetime
LVL 22

Expert Comment

ID: 38819332
the other way though you would have to either cast to datetime or use the datetime?'s value property

Author Comment

ID: 38819337
I get this compile error:
Cannot convert source type System.Nullable<System.DateTime> to target type <System.DateTime>
LVL 22

Accepted Solution

p_davis earned 500 total points
ID: 38819341
DateTime t1 = new DateTime();

DateTime? t2 = t1;

t1 = t2.Value
t1 = (DateTime)t2
LVL 44

Expert Comment

ID: 38819348
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.

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# Single Form 8 42
send messages to whatsapp programatically 2 47
compare between entities in entity framework 8 72
List<PaisEntity> - show some 1 24
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question