Confusion over the ‘|’ operator

I know that '|' means 'or' in C#, and i'm not exactly new to programming so there no confusion about that, but, for example, if i wanted to have a shortcut in my application, lets say Ctrl + Alt + P, i must use the or operator, like so:

if (keyData == (Keys.Alt | Keys.Control | Keys.P)) {}

What i want to know is why this works.. Shouldn't the code run if either Alt, Control or P is pressed, since it's an or operator, any one of the keys could qualify the expression as true. I would have thought the '&' operator would have been more appropriate, but it doesn't work. Can anyone provide an explanation for this?

by Xelerons via /r/csharp

Leave a Reply