Use Nullable Type

Use of Nullable Type, New Feature in dotNet2.0

Declare the variable as Nullable, If you want to see whether value is assigned or not.

e.g. Nullable myval=null;

Nullable types is having hasvalue and value members

if (myvalue.HasValue)
//DO something


Author: Dharmesh15 Jul 2010 Member Level: Bronze   Points : 2

Null able type feature of .net is used for the accepting null Value
It enable us for giving reference type as null.
So by getting null value compiler do not terminate the program but continue it.
int? numone=null;
if (numone.HasValue==true)
Console.WriteLine("The Value Of Numone="+numone);
Console.writeLine("The Value Of Numonw : null");

In the above code "?" sign tells that it's of null-able type
When Above code compile in the Compiler then the OUTPUT is
""Value Of Numone: null""

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: