Switch Case语句中多个值匹配一个代码块的写法

Technorati 标签: Switch Case多值用法

一直在找Switch Case语句中多个值匹配一个代码块的写法,以为像VB一样,可以用逗号分隔什么的,怎么试都不行,今天看一老外写的代码,没想到写法这样简单.
class SwichCaseTest
    {
        public static void Main(string[] args)
        {
            CaseTest(1);
            CaseTest(2);
            CaseTest(5);
            CaseTest(8);
        }
        public static void CaseTest(int i)
        {
            switch (i)
            {
                case 1:case 2:case 3:case 4:
                    Console.WriteLine("ok!**********");
                    break;
                case 5:
                    Console.WriteLine("wrong!*******");
                    break;
                default:
                    Console.WriteLine("default case!*********");
                    break;
            }
        }
    }

你可能感兴趣的:(C#,Programing,string,vb,class)