c# - 如何覆盖 &&(逻辑和运算符)?

标签 c# operator-overloading

其他一切似乎都遵循这种模式,但当我尝试时:

public static ColumnOperation operator&&(ColumnOperation lhs, ColumnOperation rhs)
{
    return new ColumnBooleanOperation(lhs, rhs, ExpressionType.And);
}

我得到“预期的可重载二元运算符”。我做错了什么?

最佳答案

不能重载条件逻辑运算符。

根据documentation :

The conditional logical operators cannot be overloaded, but they are evaluated using & and |, which can be overloaded.

This article提供有关如何实现您自己的自定义 &&|| 运算符的更多信息。

关于c# - 如何覆盖 &&(逻辑和运算符)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15439864/

相关文章:

C++:从类内访问 operator[] 的便捷方式?

c++ - 如何在嵌套类中重载 << 运算符

C++ 运算符重载和访问私有(private)数据变量

c# - 将具有单列的 DataTable 转换为以索引为键的字典

c# - Visual Studio 2015 Intellitest 不适用于 64 位项目

c# - WCF UserNamePasswordValidator 是否需要检查 PrimaryIdentity.IsAuthenticated?

c++ - 为什么标准容器迭代器不重载 `->*` ?

c++ - 为什么运算符重载无法正常执行?

c# - 是否可以在 .NET 中在运行时编译和执行新代码?

c# - 方法无法转换为 LINQ 中的存储表达式