Why must we define both == and != in C#?

后端 未结 13 2075
清酒与你
清酒与你 2020-11-27 08:55

The C# compiler requires that whenever a custom type defines operator ==, it must also define != (see here).

Why?

I\'m curious to k

相关标签:
13条回答
  • 2020-11-27 10:02

    Probably just something they didn't think of of didn't have time to do.

    I always use your method when I overload ==. Then I just use it in the other one.

    You're right, with a small amount of work, the compiler could give this to us for free.

    0 讨论(0)
提交回复
热议问题