0

I've come across this code snippet (that works) and I'm curious as to what the syntax is.

if (keyData == (Keys.Control | Keys.F)) {
    MessageBox.Show("What the Ctrl+F?");
  }

I've searched for

| Operator C#

but this merely results in links to the || OR operator.

My inital thoughts are that this could be shorthand for if (keydata == keys.Control || keydata == Keys.F) (syntax I would love to see in C#7) but this doesn't seem to be the case.

Could anyone please explain this to me?

ScottishTapWater
  • 3,656
  • 4
  • 38
  • 81
  • 3
    Bitwise OR: https://msdn.microsoft.com/en-us/library/17zwb64t.aspx – Alex K. Jan 06 '17 at 13:34
  • Also, that syntax shortcut you wanted already exists with unary operators. bool x = keydata == keys.Control || keydata == keys.F ? MessageBox.Show("What the Ctrl + F?") : DoThisIfFalse(); – CDove Jan 06 '17 at 13:38
  • @user1895086 that's not a shortcut? You've had to type `keydata ==` twice? The shortcut would be `bool x = keydata == (keys.Control||keys.f)` – ScottishTapWater Jan 06 '17 at 17:31

0 Answers0