Why overload true and false instead of defining bool operator?

前端 未结 4 1851
孤城傲影
孤城傲影 2021-02-01 06:31

I\'ve been reading about overloading true and false in C#, and I think I understand the basic difference between this and defining a bool operator. The example I see around is

4条回答
  •  不要未来只要你来
    2021-02-01 07:23

    As the docs say, overloading true and false is intended to support (nullable) database-types (Yes/No, Y/N, 0/1, etc).

    And of course you can define them inconsistently, as with any operator. It is your responsibility to return something sensible. The compiler goes no further than requiring neither or both.

提交回复
热议问题