-1

What is the difference between

if (Obj is null) Console.WriteLine("Value is null");

if (object.ReferenceEquals(Obj, null)) Console.WriteLine("Value is null");

I am trying to override the == operator and as such cannot use Obj == null.

mjwills
  • 23,389
  • 6
  • 40
  • 63
Kami
  • 19,134
  • 4
  • 51
  • 63
  • Since `object.ReferenceEquals()` internally is `==` check ([ReferenceEquals](https://referencesource.microsoft.com/#mscorlib/system/object.cs,4d607d6d56a93c7e,references)), then: Possible duplicate of [What is the difference between "x is null" and "x == null"?](https://stackoverflow.com/questions/40676426/what-is-the-difference-between-x-is-null-and-x-null) – Sá´‡M May 21 '19 at 10:38

1 Answers1

0

ReferenceEquals(obj, null) and (obj is null) do exactly the same thing, but the latter is only available as part of C# 7.0 syntax and later.

Matthew Layton
  • 39,871
  • 52
  • 185
  • 313
Steve Todd
  • 1,250
  • 6
  • 13