Assigning null value to DateTime - Bill Gower

14-Feb-07 11:10:12
How do I assign a null value to a datetime variable?

DateTime DateNonMember = DateTime.Parse("").ToString();

This doesn't work.

I also tried

DateTime DateNonMember = DBNull.Value


Bill
button
 
 

Assigning null value to DateTime - Jon Skeet [C# MVP]

14-Feb-07 11:21:35
You can't. DateTime is a value type, like int, char and boolean.
(That's not an exhaustive list!)

If you're using .NET 2.0, you can use DateTime? which is a nullable
version of DateTime. See
http://pobox.com/~skeet/csharp/csharp2/nullable.html for more
information.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
button
 

Assigning null value to DateTime - Tim Van Wassenhove

14-Feb-07 11:23:21
Bill Gower schreef:


DateTime is a value type so you can't assign null to it.
You can assign null to Nullable<DateTime> (DateTime? in c#)


--
Tim Van Wassenhove <url:http://www.timvw.be/>
button
 
DirectX to GDI