PC Review


Reply
Thread Tools Rate Thread

Casting null values

 
 
Microsoft Newsserver
Guest
Posts: n/a
 
      23rd Jun 2008
Hi,

Im having a bit of difficulty working out how to do the following.


method ( paramType? param1, DateTime? requiredByDate , paramType? param3)


I have a row property which I need to pass to this method, this has a
property of IsNull which is a boolean, so I tried to do the following

method ( param1,
row.IsRequiredByDateNull() ? null, row.RequiredByDate,
param3 )

This fails on compile because it cant cast from a null to a DateTime.

How can i construct this ?


 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      23rd Jun 2008
Microsoft Newsserver <(E-Mail Removed)> wrote:
> Im having a bit of difficulty working out how to do the following.
>
>
> method ( paramType? param1, DateTime? requiredByDate , paramType? param3)
>
>
> I have a row property which I need to pass to this method, this has a
> property of IsNull which is a boolean, so I tried to do the following
>
> method ( param1,
> row.IsRequiredByDateNull() ? null, row.RequiredByDate,
> param3 )
>
> This fails on compile because it cant cast from a null to a DateTime.
>
> How can i construct this ?


Don't cast to DateTime - cast to DateTime? (with the question mark).
Then it should be fine.

--
Jon Skeet - <(E-Mail Removed)>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
 
Reply With Quote
 
Microsoft Newsserver
Guest
Posts: n/a
 
      23rd Jun 2008

should have read

row.IsRequiredByDateNull() ? null : row.RequiredByDate;





"Microsoft Newsserver" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> Im having a bit of difficulty working out how to do the following.
>
>
> method ( paramType? param1, DateTime? requiredByDate , paramType?
> param3)
>
>
> I have a row property which I need to pass to this method, this has a
> property of IsNull which is a boolean, so I tried to do the following
>
> method ( param1,
> row.IsRequiredByDateNull() ? null, row.RequiredByDate,
> param3 )
>
> This fails on compile because it cant cast from a null to a DateTime.
>
> How can i construct this ?
>



 
Reply With Quote
 
Micha³ Piaskowski
Guest
Posts: n/a
 
      23rd Jun 2008
On Jun 23, 5:16 pm, "Microsoft Newsserver" <m...@nowhere.com> wrote:
> should have read
>
> row.IsRequiredByDateNull() ? null : row.RequiredByDate;
>
> "Microsoft Newsserver" <m...@nowhere.com> wrote in message
>
> news:(E-Mail Removed)...
>
> > Hi,

>
> > Im having a bit of difficulty working out how to do the following.

>
> > method ( paramType? param1, DateTime? requiredByDate , paramType?
> > param3)

>
> > I have a row property which I need to pass to this method, this has a
> > property of IsNull which is a boolean, so I tried to do the following

>
> > method ( param1,
> > row.IsRequiredByDateNull() ? null, row.RequiredByDate,
> > param3 )

>
> > This fails on compile because it cant cast from a null to a DateTime.

>
> > How can i construct this ?


I once had the same problem.
I can't check it with a compiler right now, but the solution is
something like this:

row.IsRequiredByDateNull() ? (DateTime?)null : row.RequiredByDate;
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display queried records with Null values (null recordcount) Mishanya Microsoft Access Getting Started 6 25th Jan 2009 06:53 PM
Empty text values aren't null or zero-length, but 2-byte null (\x0000) Mark Steward Microsoft Access 2 21st Jan 2006 02:03 PM
Null Casting Error when using Strongly-Typed Dataset C Newby Microsoft ADO .NET 1 26th Mar 2004 06:54 PM
Casting Null values Brad Allison Microsoft ADO .NET 1 26th Nov 2003 12:57 PM
Casting Datarow values Venkatesh Microsoft ADO .NET 0 31st Oct 2003 10:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:36 AM.