c#笔记(四)——switch

switch (date)
            {
                case 1:
                    Console .WriteLine("周一" );
                    break ;
                case 2:
                    Console .WriteLine("周二" );
                    break ;
                case 3:
                    Console .WriteLine("周三" );
                    break ;
                case 4:
                    Console .WriteLine("周四" );
                    break ;
                case 5:
                    Console .WriteLine("周五" );
                    break ;
                case 6:
                    Console .WriteLine("周六" );
                    break ;
                case 7:
                    Console .WriteLine("周日" );
                    break ;
                default :
                    Console .WriteLine("大保健" );
                    break ;
            }
1.switch里面可以没有default语句块,如果所有的case都不符合要求时
            会直接跳出switch开关
            2.如果case后面有语句,则一定要有break
            3.如果case后面没有任何代码,它会和他后面的case共用一段代码
            4.default的位置是随意的
            5.case的位置不确定
posted @ 2016-09-29 21:44  无畏先锋  阅读(167)  评论(0编辑  收藏  举报