How to find if the value is null for a Nullable Type in c# ?

The Nullable type in C# provides the property HasValue which can be used to find if the value is null . Below is a sample sourecode snippet demonstrating How to find if the value is null for a Nullable Type in c# ?

How to find if the value is null for a Nullable Type in c# ?

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication1

{

internal class Program

{

// Abundantcode - Demonstrate HasValue

private static void Main(string[] args)

{

int? Input = null;

if (Input.HasValue)

Console.WriteLine("The value is not null");

else

Console.WriteLine("The value is null");

Console.ReadLine();

}

}

}
How to find if the value is null for a Nullable Type in c# ?