开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜