In C #, what does' | = '?
I can't seem to google it, it's like the syntax in the search bar. Thanks for the help.
This is a bit of a wise assignment. This is roughly shortened for the following
x |= y; x = x | y;
Note. This is not the case because the C # specification ensures that side effects x
only appear once. Therefore, if it x
is a complex expression, a fun bit of code is generated for the compiler to ensure that side effects only happen once.
Method().x |= y;
Method().x = Method().x | y; // Not equivalent
var temp = Method();
temp.x = temp.x | y; // Pretty close
Expression is a |= b
equivalent to assignment a = a | b
, where |
is the bitwise OR operator. *
* Not quite, but close enough for most purposes.
He likes +=
it but with a binary OR
int x = 5;
x |= 6; // x is now 7: 5 | 6
You can also do the other, such as &=
, /=
, *=
, etc. Almost any binary (two arguments) operator
In C and other languages that follow C syntactic conventions such as C ++, Perl, Java, and C #, (a | b) denotes bitwise or; while the double vertical bar (a || b) denotes (short-circuited) logical or.
a |= b
semantically matches a = a | b
| = is a bitwise assignment operator. Check out the msdn documentation here http://msdn.microsoft.com/en-us/library/h5f1zzaw(v=vs.100).aspx
you will find the answer here at msdn
x |= y
coincides with
x = x | y
http://msdn.microsoft.com/en-us/library/h5f1zzaw(v=vs.80).aspx is your specific
http://msdn.microsoft.com/en-us/library/6a71f45d(v=vs.80).aspx if you're curious and want a full list