#174 – 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 switch expression has a value matching any of the listed case statements, the corresponding code will be executed.

            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;
            }

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 43 other followers