Prev: Windows service
Next: Interrupting a native thread
From: Denise on 5 May 2010 03:04 You can assign 0 into datetime field. DateTime DateNonMember = 0 ; Bill Gower wrote: Assigning null value to DateTime 14-Feb-07 How do I assign a null value to a datetime variable? DateTime DateNonMember = DateTime.Parse("").ToString(); This does not work. I also tried DateTime DateNonMember = DBNull.Value Bill Previous Posts In This Thread: On Wednesday, February 14, 2007 11:10 AM Bill Gower wrote: Assigning null value to DateTime How do I assign a null value to a datetime variable? DateTime DateNonMember = DateTime.Parse("").ToString(); This does not work. I also tried DateTime DateNonMember = DBNull.Value Bill On Wednesday, February 14, 2007 11:21 AM Jon Skeet [C# MVP] wrote: Re: Assigning null value to DateTime Bill Gower <billgower(a)charter.net> wrote: 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(a)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 On Wednesday, February 14, 2007 11:23 AM Tim Van Wassenhove wrote: Re: Assigning null value to DateTime Bill Gower schreef: DateTime is a value type so you cannot assign null to it. You can assign null to Nullable<DateTime> (DateTime? in c#) -- Tim Van Wassenhove <url:http://www.timvw.be/> Submitted via EggHeadCafe - Software Developer Portal of Choice Server Side Processing in ADO.NET/WCF Data Services http://www.eggheadcafe.com/tutorials/aspnet/db179aed-47fa-4f86-a4bf-4f6f92a76585/server-side-processing-in.aspx
From: Family Tree Mike on 5 May 2010 08:44 On 5/5/2010 3:04 AM, Denise Ch wrote: > You can assign 0 into datetime field. > DateTime DateNonMember = 0 ; > No, that does not compile as written because there is no conversion from int to System.DateTime. Jon Skeet provided the correct answer, which was using: DateTime? DateNonMember = null; -- Mike
From: Arne Vajhøj on 5 May 2010 19:00 On 05-05-2010 03:04, Denise Ch wrote: >> Bill Gower wrote: >> >> Assigning null value to DateTime >> 14-Feb-07 >> >> How do I assign a null value to a datetime variable? >> >> DateTime DateNonMember = DateTime.Parse("").ToString(); >> >> This does not work. >> >> I also tried >> >> DateTime DateNonMember = DBNull.Value > You can assign 0 into datetime field. > DateTime DateNonMember = 0 ; Not only do you reply to a 3 year old question, but you also reply with an incorrect answer. Arne
From: Arne Vajhøj on 5 May 2010 19:02 On 05-05-2010 08:44, Family Tree Mike wrote: > On 5/5/2010 3:04 AM, Denise Ch wrote: >> You can assign 0 into datetime field. >> DateTime DateNonMember = 0 ; > > No, that does not compile as written because there is no conversion from > int to System.DateTime. Jon Skeet provided the correct answer, which was > using: > > DateTime? DateNonMember = null; And if that solution for whatever reason (like existing API) is not possible, then "magic values" like DateTime.MinValue is the possible (but not very good) solution. Arne
|
Pages: 1 Prev: Windows service Next: Interrupting a native thread |