Reputation: 2780
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.
Upvotes: 9
Views: 14354
Reputation: 2912
You know how x += 1
means x = x + 1
, well x |= 1
means x = x | 1
. Of course |
means bitwise OR.
Upvotes: 29