Result of calling IEquatable.Equals(T obj) when this == null and obj == null?

前端 未结 7 619
鱼传尺愫
鱼传尺愫 2021-01-12 07:05

What should IEquatable.Equals(T obj) do when this == null and obj == null?

1) This code is generated

7条回答
  •  余生分开走
    2021-01-12 07:34

    I would definitelly go with option 1:

        if (this == null)
        {
            return obj == null;
        }
        if (obj == null)
        {
            return false;
        }
    

    null object always equals null object.

提交回复
热议问题