This post will discuss how to check if an object is null in C#.

There are several ways to check if an object is null in C#:

1. ‘is’ constant pattern

Starting with C# 7.0, the is operator supports testing an expression against a pattern. The null keyword is supported by the is statement. We can check the null using the constant pattern. The following example shows its usage:

Download

2. Equality operator (==)

Another standard way to check for the null object in C# is to use the equality operator (==). This is demonstrated below:

Download  Run Code

3. Using Object.ReferenceEquals method

The Object.ReferenceEquals() method determines whether the specified Object instances are the same instance. It returns true if both object instances are null.

Download  Run Code

That’s all about determining whether an object is null in C#.