简体   繁体   English

| =运算符是什么意思?

[英]What does the |= Operator mean?

In some code i found this |= operator used to return a uint but i can find something about it on the internet and i wanna understand how it works and what are the return values in this case. 在一些代码中我发现这个|=运算符用于返回一个uint但我可以在互联网上找到它的一些东西,我想了解它是如何工作的,在这种情况下返回值是什么。

public uint Mask
{
    get
    {
        uint num = 0;
        if (_0)
            num |= 1U;
        if (_1)
            num |= 2U;
        if (_2)
            num |= 4U;
        return num;
    }
}

a detailed answer will be much appreciated. 将非常感谢详细的答案。

You know how x += 1 means x = x + 1 , well x |= 1 means x = x | 1 你知道x += 1表示x = x + 1 ,井x |= 1表示x = x | 1 x = x | 1 . x = x | 1 Of course | 当然| means bitwise OR. 表示按位OR。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM