C#

C#

Made by DeepSource

Pointer is being compared with null CS-W1063

Bug risk
Critical
Autofix

Languages such as C and C++ allow you to compare pointers with variants of null such as NULL and nullptr. This practice, however, is not acceptable in C#. Only reference types are meant to be compared with null. Pointers, however, should be compared with appropriate values such as IntPtr.Zero.

Bad Practice

if (ptr == null)
{
    // pointer is `null`!
}

Recommended

if (ptr == IntPtr.Zero)
{
    //
}

Reference