Saturday, 26 January 2013

Declare null variable in C#



int? myInt = null;
bool? myBool = null;

You can declare any type of variable like mentioned above.


example : 


using System;
class MyPoint
{
static void Main()
{
int? myInt = null;
bool? myBool = null;
float? myFloat = 1.23F;
char? myChar = 'C';


Console.WriteLine("myInt = {0}\n"+
"myBool = {1}\n" +
"myFloat = {2}\n" +
"myChar = {3}\n",
myInt, myBool, myFloat, myChar);
}
}

Output:
myInt =
myBool =
myFloat = 1.23
myChar = C


Enjoy.................

No comments:

Post a Comment