语句(switch语句及其内case , break)

 /* C#:语句     判断,循环,形成循环的分支和循环                

选择控制:if    else,     switch    case                

选择控制:while,do,for.foreach                

跳转语句:break,continue                

异常处理:try,catch,finally             

*/            /* int casezhi = 1;            

switch (casezhi)    //小括号内是一个数据类型的值           

  {                 //case 后面加空格,之后写上跟小括号内对应类型的 可能出现的值              

   case 1:                    

   Console.Write("");                  

   break;         //跳转语句。  跳出 包含break 最近的{}!               

  case 2:                    

   Console .Write ("");                    

   break;                

   default :                       

  Console.Write("");                 

    break;            

}            

Console.ReadLine();*/            

           /* //练习,判断2014年a月第b天是这一年的第几天        

     Console.WriteLine("输入月:");           

  int a = int.Parse(Console.ReadLine());          

   Console.WriteLine("输入日:");        

    int b = int.Parse(Console.ReadLine());                

   int c=1;

            switch (a)          

   {                 case 1:

                    c=b; //前面已经创建了int c,所以这里不能再创建int c=b,可以直接赋值即c=b.                        

                      break;             //必须有    break

                        case 2:                   

                        c = 31 + b;                

                       break;             

                       case 3:                  

                       c = 31 +28+ b;               

                         break;              

                          case 4:            

                        c = 31 + 28 +30+ b;             

                            break;

                          case 5:

                        c = 31 + 28 +31+30+ b;

                           break;

                case 6:                           c = 31 + 28 +31+30+31+ b;                                 break;                

                case 7:                c = 31 + 28 + 31 + 30 + 31 + 30 + b;                                break;                 case 8:             c = 31 + 28 + 31 + 30 + 31 + 30 +31+ b;                             break;                 case 9:               c = 31 + 28 + 31 + 30 + 31 + 30 + 31 +31 +b;                     break;                 case 10:          c= 31 + 28 + 31 + 30 + 31 + 30 + 31 +31+30+ b;                     break;                 case 11:          c = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 +31+ b;         break;

                       default:           // 最后的例子!

                    c = 31 +28+31+30+31+30+31+31+30+31+30+ b;

                    break;

 }             //Console.Write("这是第" + c + "天");              //注意引用格式!                Console.WriteLine("这是第" + c.ToString()  + "天");//.ToString()表示把引用的c转义为字符串型!Console.ReadLine ();             

*/            

posted @ 2014-10-14 12:59  安定祥和  阅读(1279)  评论(0编辑  收藏  举报