null
CS-W1063Languages 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
.
if (ptr == null)
{
// pointer is `null`!
}
if (ptr == IntPtr.Zero)
{
//
}