C# 中的按位赋值运算符
像 |=
和 &=
这样的运算符在整数和长整数上用作按位运算符...
int a = 123;
int b = 234;
a |= b;
Console.WriteLine(a); // outputs 251
但在布尔值上,这是一个逻辑运算:
bool a = true;
bool b = false;
a |= b;
Console.WriteLine(a); // outputs true
^ 是如何工作的=
、&=
和 |=
运算符决定在应用于不同数据类型时使用哪种操作?
Operators like |=
and &=
work as bitwise operators on ints and longs...
int a = 123;
int b = 234;
a |= b;
Console.WriteLine(a); // outputs 251
But on a bool, it's a logical operation:
bool a = true;
bool b = false;
a |= b;
Console.WriteLine(a); // outputs true
How do the ^=
, &=
and |=
operators decide which manipulation to use when being applied to different data types?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编译器根据所涉及表达式的静态类型来决定。
The compiler decides, based on the static types of the expressions involved.