Why overload true and false instead of defining bool operator?

前端 未结 4 1794
孤城傲影
孤城傲影 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:29

    I've seen people overload the true and false overloads in order to do clever things like building expressions in .NET 2.0, before Linq existed.

    Ayende worked out a syntax like this to build NHibernate criteria queries, using his NHQG project:

    return Repository.FindAll(
        (Where.Publisher.Name == name) &&
        (Where.Publisher.City == city));
    

提交回复
热议问题