assign null value to datetime

  • Thread starter Thread starter vince
  • Start date Start date
Since DateTime is a Value Type (not a Reference Type), so you can't assign
null or Nothing to it. If you want to do something simelar, you could use
the MinValue property:

if(myDate == DateTime.MinValue)
{
//myDate is empty
}

Or you can use the Nullable Types library:
http://nullabletypes.sourceforge.net/

Jan
 
You cannot assign null value to datetime because it's
structure not a class. Stucture has to always has a value.

Jan.
 
MSDN:
"Unlike reference types, it is not possible for a value type to contain the
null value."

DateTime is a value type.

--
Horatiu Ripa
Software Development Manager
Business Logic Systems LTD
21 Victor Babes str., 1st floor, 3400 Cluj-Napoca, Romania
Phone/Fax: +40 264 590703
Web: www.businesslogic.co.uk

This email (email message and any attachments) is strictly confidential,
possibly privileged and is intended solely for the person or organization to
whom it is addressed. If you are not the intended recipient, you must not
copy, distribute or take any action in reliance on it. If you have received
this email in error, please inform the sender immediately before deleting
it. Business Logic Systems Ltd accepts no responsibility for any advice,
opinion, conclusion or other information contained in this email or arising
from its disclosure.
 
Sorry Vince, it is a value type, so it can't be null. I usually work around
this by assigning DateTime.MinValue as the "null" value.

Regards

Ron
 
Back
Top