In VB.NET there is such a construction:

Case Keys.Control Or Keys.D1, Keys.Control Or Keys.NumPad1 

Ie, separated by commas, you can list 2 cases.

Is there anything like this in C #?

Or something like this in C # is written like this:

 case Keys.Control | Keys.D1: case Keys.Control | Keys.NumPad1: { break; } 

?

  • In Java, so case Keys.D1: case Keys.NumPad1: {break; } Maybe in C # also - JavaJunior

1 answer 1

Write case blocks one by one, control will be transferred down to the first break / return / etc.

 int i = 0; switch (i) { case 0: case 1: case 2: // какое-то действие, общее для всех трех вариантов break; case 3: case 4: case 5: // другое общее действие break; }