Using nullable types in C#

Posted by Martin Brown on Stack Overflow See other posts from Stack Overflow or by Martin Brown
Published on 2008-11-03T18:19:07Z Indexed on 2010/04/07 2:43 UTC
Read the original article Hit count: 460

Filed under:
|
|

I'm just interested in people's opinions. When using nullable types in C# what is the best practice way to test for null:

bool isNull = (i == null);

or

bool isNull = !i.HasValue;

Also when assigning to a non-null type is this:

long? i = 1;
long j = (long)i;

better than:

long? i = 1;
long j = i.Value;

© Stack Overflow or respective owner

Related posts about c#

Related posts about nullable-types