C#学习2--流程控制

       流程控制

一、条件语句

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”);

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值