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(逻辑双条件)运算符?


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01