Is there XNOR (Logical biconditional) operator in C#?(C# 中是否有 XNOR(逻辑双条件)运算符?)
问题描述
我是 C# 新手,找不到 XNOR 运算符来提供这个真值表:
<上一页>a b a XNOR b----------------T T T对了F T FF F T是否有专门的运营商来做这件事?或者我需要使用 !(A^B)?
XNOR 只是布尔值上的相等;使用 A == B
.
这很容易被忽略,因为相等性通常不应用于布尔值.并且有些语言不一定有效.例如,在 C 中,任何非零标量值都被视为真,因此两个真"值可能不相等.但是问题被标记为 c#,它有,容我们说,表现良好的布尔值.
另请注意,这并不适用于按位运算,您需要 0x1234 XNOR 0x5678 == 0xFFFFBBB3
(假设为 32 位).为此,您需要从其他操作构建,例如 ~(A^B)
.(注意:~
,而不是 !
.)
I'm new to C# and could not find XNOR operator to provide this truth table:
a b a XNOR b ---------------- T T T T F F F T F F F T
Is there a specific operator for this? Or I need to use !(A^B)?
XNOR is simply equality on booleans; use A == B
.
This is an easy thing to miss, since equality isn't commonly applied to booleans. And there are languages where it won't necessarily work. For example, in C, any non-zero scalar value is treated as true, so two "true" values can be unequal. But the question was tagged c#, which has, shall we say, well-behaved booleans.
Note also that this doesn't generalize to bitwise operations, where you want 0x1234 XNOR 0x5678 == 0xFFFFBBB3
(assuming 32 bits). For that, you need to build up from other operations, like ~(A^B)
. (Note: ~
, not !
.)
这篇关于C# 中是否有 XNOR(逻辑双条件)运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# 中是否有 XNOR(逻辑双条件)运算符?


- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01