开发者

What is the operator `|=`? How can I implement this in C#?

开发者 https://www.devze.com 2023-02-21 02:12 出处:网络
What is the C++ code below doing? More specifically, what is the operator |=? long liFaultFlags = 0; for (int i = 0; i < FAULTCOUNT; i++)

What is the C++ code below doing? More specifically, what is the operator |=?

long liFaultFlags = 0;

for (int i = 0; i < FAULTCOUNT; i++)
{
    if (faults[i] == true)
    {
        liFaultFlags |= (1 <&l开发者_运维技巧t; i);
    }
}

return liFaultFlags;

How would this be implemented in C#?


It is the bitwise OR operator and is equivalent to

liFaultFlags = liFaultFlags | (1<<i);

You would write that line in exactly the same way in C#.


The operator |= does bitwise OR and assignment rolled into one (much like += does integer addition and assignment together).

It's exactly the same in C#.

0

精彩评论

暂无评论...
验证码 换一张
取 消