NullReferenceException
when comparing against null
CS-W1019The .Equals
method works only when the object upon which it is being called is non-null
. In case a method such as .Equals
is called on an object that is null, a NullReferenceException
is thrown. Instead, to check if an object
is truly null
, consider using the ==
or !=
operators instead.
var isNull = someObject.Equals(null); // NullReferenceException
var isNull = someObject == null;