Dict.CN 在线词典, 英语学习, 在线翻译 ------------- MyGitee 朱秋贵内科诊所 My腾云code

C#流程控制

一、条件语句

1.  If语句

If(boolean){}else{}

2.  Switch语句

Switch(表达式){

Case 分支1:

        。。。。

        break;

case 分支2:

        ….

        Break;

Default:

        Break;}

表达式可以是string,enum,char,int

break;为必须

二、循环语句

1.  For

For(int I=0; I<10; I++)

{}

2.  Foreach

Foreach (object a in list){}

3.  While

While(条件){}

4.  Do-while

Do{

}while(条件)

三、跳转语句

1.  Goto

Label1:

Int a=0;

DoSomething();

        If (a==10)

        Goto Label1:

在switch中用法

goto case 1;

goto default

 

2.  Break 在switch语句和循环语句中

3.  Continue 在循环语句中

4.  Return 在过程中

四、异常处理

1.  捕获异常

try{

for(;n<=max; n++)

sum* = n;

}

catch(OverflowException e)

{

Console.WriteLine(“溢出了”);

 Return;

}

2.  清除异常

finally{

        ….

}

3.  处理所有异常

catch(OverflowException oe)

{

}

catch(Exception e)

{

}

4.  抛出异常

throw new Exception(“error”);

posted @ 2008-03-19 15:00  cn2024  阅读(164)  评论(0编辑  收藏  举报