c# - |= 运算符是做什么的?

标签 c#

<分区>

Possible Duplicate:
what does |= (single pipe equal) and &=(single ampersand equal) mean in c# (csharp)

这里是它被使用的上下文:

long dirtyFlag = 0x0000;

if (erd.SupervisorCompType != orgErd.SupervisorCompType) // change has been made?
{
   dirtyFlag |= 0x0001;
   // etc...
}

最佳答案

dirtyFlag |= 0x0001 等同于 dirtyFlag = dirtyFlag | 0x0001| 运算符是按位或运算符。在您的情况下,它设置最低的二进制位。一些进一步的例子:

1 | 2 = 3 (0001 | 0010 = 0011)
2 | 4 = 6 (0010 | 0100 = 0110)
5 | 1 = 5 (0101 | 0001 = 0101)

关于c# - |= 运算符是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12868127/

相关文章:

c# - 将 xml 数据存储在 cookie 中

c# - 如何获取嵌入资源的资源Uri?

c# - ASP.NET 4.0 中的堆积柱形图

c# - 使用键盘上的 Enter 等同于计算器

c# - 转换可为空的 bool 值? bool

c# - C#中指定 block 内的XmlDocument GetElementsByTagName

c# - 如何从网络摄像头捕捉视频?

c# - Asp.Net/C# - 如何获取嵌套在 Repeater 中的 Label 控件的文本?

c# - 通过命令行传递安装路径 - installshield

c# - 读取大文件时内存不足