Group case statements together

We can group statements together to shorten the code.


using System;

class Program
{
    static void Main(string[] args)
    {
        string ch = "C";
        switch (ch)
        {
            case "A":
            case "B":
            case "C":
                Console.WriteLine("Pass");
                break;
            case "D":
            case "E":
                Console.WriteLine("Failed");
                break;
        }

    }
}

The output:


Pass
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.