分支判断--asp.net

1.if...else

  

    //if else实例
                string wo = "天轰穿";
                if (wo == "天轰穿")
                {
                    Label1.Text ="我知道你是天轰穿";
                }
                else {
                    Label1.Text ="老实交代,你到底是哪个?";

            }

 

2.try ...catch

          try
                {
                    string a = "肯定转换不了";
                    int b = Convert.ToInt32(a);
                }
                catch
                {
                    Response.Write("不能将文本字符转换成Int类型,你吃错药啦!");       
                }
 

 

3.switch...case...default

  int abc = 8;
                switch (abc)
                { 
                    case 1:
                        Label2.Text = "等于1";
                        break;
                    case 2:
                        Label2.Text = "等于2";
                        break;
                    case 5:
                        Label2.Text = "哈哈,对了,就是5";
                        break;
    
                    default :
                        Label2.Text = "都不是";
                        break;
                }

  

1).一定要有一个break

2).switch针对基本的数据类型,int string

3).case 唯一

4).case必须是常量表达式

posted @ 2015-04-20 17:29  ZeroWM  阅读(200)  评论(0编辑  收藏  举报