Multiple Case Statements in switch Statement Can Share Code

In a C# switch statement, you can group several case statements with the same block of code.  If the switchexpression has a value matching any of the listed case statements, the corresponding code will be executed.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
switch (movieRating)    // 1-5
{
    case 1:
    case 2:
        Console.WriteLine("Not worth seeing");
        break;
    case 3:
    case 4:
        Console.WriteLine("Consider seeing it");
        break;
    case 5:
        Console.WriteLine("Absolutely must see it");
        break;
}