5

I have an object of type T which implements IComparable<T>. Is it okay when implementing bool Equals (T obj) to ommit the check if (ReferenceEquals(this, null)) { DoSomething() }? Can I assume that since the function could be called this is already not null?

Thank you very much.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Miguel
  • 51
  • 1

2 Answers2

3

Yes you can assume that if the function has been called on an object, then that object is not null.

Nick
  • 25,026
  • 7
  • 51
  • 83
3

You should always assume this != null, because C# guarantees it.

Gabe
  • 84,912
  • 12
  • 139
  • 238