December 2006 Entries

Identity among Objects

Objects static method ReferenceEquals() uses == oprator to compare two references. The C# compiler generates the IL that is being generated when two objects are being compared with == operator like (obj1==obj2). But there a catch to the whole thing... You can write either ReferenceEquals() or == to compare two objects,, as you prefer them.However you need to very careful. The == operator is guaranteed to check identity only if the variables on both sides of the == operator are of the System.Object...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati