9

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.

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.

Daniel Eugen
  • 2,712
  • 8
  • 33
  • 56

1 Answers1

29

You know how x += 1 means x = x + 1, well x |= 1 means x = x | 1. Of course | means bitwise OR.

LordWilmore
  • 2,829
  • 2
  • 25
  • 30