The following code shows how to define an integer as nullable type and checks if the value of the integer is null or not.
Example
/// <summary>
/// Nullable types
/// </summary>
public static void TestNullableTypes()
{
// Syntax to define nullable types
int? counter;
counter = 100;
if (counter != null)
{
// Assign null to an integer type
counter = null;
Console.WriteLine("Counter assigned null.");
}
else
{
Console.WriteLine("Counter cannot be assigned null.");
Console.ReadLine();
}
}
If you remove the "?" from int? counter, you will see a warning as following:
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:
Post a Comment