C#控制流语句(六)
条件执行语句
if语句
1 | if (<test>) |
if…else语句
1 | if (var1 == 1) |
1 | if (var1 == 1) |
switch语句
1 | switch (<testVal>) |
1 | for( int x=1; x<6; x++ ) |
1 | x is 1 -- In Default case |
循环语句
while语句
1 | while (<Test>) |
do循环
1 | do |
for循环
1 | for(<initialization>; <condition>; <operation>) |
等价于
1 | <initialization>; |
for语句中变量的作用域
初始化和迭代表达式中的多表达式
1 | static void Main() |
跳转语句
break:立即终止循环continue:立即终止当前的循环(执行下一次循环)return:跳出循环及包含该循环的函数
break语句
continue语句
goto语句
1 | bool thingsAreFine; |
using语句
1 | using System; //using 指令,不是 using 语句 |
其他语句
| 语句 | 描述 |
|---|---|
checked、unchecked |
控制溢出检查上下文 |
foreach |
遍历一个集合的每个成员 |
try、throw、finally |
处理异常 |
return |
将控制返回到调用函数的成员,而且还能返回一个值 |
yield |
用于迭代 |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 StackPub!
