Reputation: 180
from the C# 7 we have available is
pattern matching operator. I would like to ask if it is recommended to use is
operator rather than ==
to check for null
. Is there any difference between these two approaches?
Upvotes: 2
Views: 190
Reputation: 4963
==
can be customized on your type, so x == null
may not be just the intended null check.
For a null check, you could do x is null
, (object)x == null
or object.ReferenceEquals(x, null)
.
Upvotes: 3