Wednesday, January 20, 2010

Handling Null value in case of value type.

Hello friends,

As we can check for null values in case of Reference type.
What if want to do the same with value type.
Here the new feature of .net do it for you.

public int? x;
public int? X
get { return x; }

Now you can check
if( X != null) or if ( X == null)

Note:- Needed to be type cast to (int) where need int value.
Use:- Very usefull suppose you declared any field as integer in database table.
And you forget to declared default value as 0 (zero).
Then whenever you query to database you get a null value so it can be used for checking that.

No comments:

Post a Comment