^ 运算符真的是 C# 中的 XOR 运算符吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1508153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:15:42  来源:igfitidea点击:

Is the ^ operator really the XOR operator in C#?

c#operatorsxor

提问by RCIX

I read that the ^operator is the logical XOR operator in C#, but I also thought it was the "power of" operator. What is the explanation?

我读到^运算符是 C# 中的逻辑 XOR 运算符,但我也认为它是运算符的“力量”。解释是什么?

采纳答案by Lasse V. Karlsen

It is not the power of operator of C# since there is no such operator in C#. It is just the XOR operator.

这不是 C# 运算符的威力,因为 C# 中没有这样的运算符。它只是 XOR 运算符。

For "power of", use Math.Pow.

对于“力量”,请使用Math.Pow

As you can see from this page on the C# Operators, ^is listed under the "Logical (boolean and bitwise)" category, which means it can both handle boolean values, and binary values (for bitwise XOR).

正如您从C# Operators上的这个页面看到的那样,^它列在“逻辑(布尔和按位)”类别下,这意味着它既可以处理布尔值,也可以处理二进制值(用于按位异或)。