C#

C#

By DeepSource

Potential NullReferenceException when comparing against null CS-W1019

Bug risk
Autofix

The .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.

Examples

Bad Practice

var isNull = someObject.Equals(null); // NullReferenceException

Recommended

var isNull = someObject == null;

Reference