Possible Duplicate:
What is the diffference between the | and || or operators?
What does | (pipe) mean in c#?
I have some code that was written by another developer in the office, who isn’t in at the moment. I have some work to do on his code, but I have not coma across this before. I tried searching on here, but it strips my | out of the search line. I also don’t know what the name for that symbol is, so couldn’t search for it like that.
this.Action.Values[key] = (int)this.Action.Values[key] | 1;
My question is what does the single or do in this instance?
The Bar (or pipe),
|is a bit-wiseORoperator, and the easiest way of explaining it is that it allows us to combine flags. Consider:Using the bitwise-OR operator, we can combine flags, thusly:
We can “test” for a given flag, using:
Removing flags is a bit more of a strain on the eyeballs: