↑ Grab this Headline Animator

Monday, November 17, 2008

Nullable type for Value types in C#

we cant initialize a value type variable with null, as it holds data directly unlike as refernce type which just have the refernce to the memory location.

int i = 0; //Correct

int i = Null; //Wrong.

In C# 2.0 we have Nullable types. Syntax asn usage is as below.

int ?i = null;

For Nullable types by default we get two properties HasValue,Value.
HasValue is a boolean value and it gives true if Nullable type has some value other than null else it gives false.
Value gives the value of Nullable Type variable i.

Submit this story to DotNetKicks

No comments:

Post a Comment

Post your comments/questions/feedback for this Article.


Latest Articles