How to determine whether object reference is null?

Viewed 55571

What is the best way to determine whether an object reference variable is null?

Is it the following?

MyObject myObjVar = null;
if (myObjVar == null)
{
    // do stuff
}
5 Answers

In C# 7.0 you can use is null:

MyObject myObjVar = null;
if (myObjVar is null)
{
    // do stuff
}
Related