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


This content was proof-read by Grammarly. You can Try Grammary for FREE

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# ?
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: