It's Microsoft's World, and I'm just living in it
View Clarence Klopfstein's profile on LinkedIn

Clarence Klopfstein's Facebook profile

This site is under construction...


New Comments

Referring Sites


  • This is MY blog. The views represented here are not in relation to anybody else. Please read my full disclaimer for a more complete disclaimer.

Nullable Int type in C#

August 18, 2008 03:00 by ckincincy

I was recently doing some development that needed to allow for an int to be null.  However in .NET that isn't allowed by default.

So I started doing some searches and found that there is a way to have nullable types in C#.

There are two ways to do this:

1. Nullable<int> x = new Nullable<int>(125);

2. int? x = 125

Now what I find interesting is how you can find out if this is null.  You can do, again, one of two things.

1. if(x.HasValue).....

2. if(x != null)....

I actually prefer option two in both situations because that just looks normal to me. 

HT: Eric Gunnerson

Comments are closed