Question about |= in c#
开发者_StackOverflow社区What means |= in c#?
Example:
int a= 0;
int b = a |= 5;
I can't find any hints for this.
the OR assignment operator.
full explanation is here. http://msdn.microsoft.com/en-us/library/h5f1zzaw(v=vs.71).aspx
|= is the OR assignment operator.
http://msdn.microsoft.com/en-us/library/h5f1zzaw.aspx
"|" is a bitwise OR operator. http://msdn.microsoft.com/en-us/library/kxszd0kx(v=vs.71).aspx
So,
a |= 5;
is the same as
a = a | 5;
This is in the MSDN Library under operators for c#
http://msdn.microsoft.com/en-us/library/h5f1zzaw.aspx
It is an assignment operator that performs a bitwise logical OR on integral operands and a logical OR on bool operands.
http://msdn.microsoft.com/en-us/library/h5f1zzaw(v=VS.100).aspx
Bitwise or.
Your snippet becomes.
int a = 0;
int b;
a = a | 5;
b = a;
In the end, a = b = 5
精彩评论