Assuming this != null when implementing IComparable<T>
I have an ob开发者_运维技巧ject 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.
Yes you can assume that if the function has been called on an object, then that object is not null
.
You should always assume this != null
, because C# guarantees it.
精彩评论