控制C#中的程序流程

时间:2020-02-23 14:29:51  来源:igfitidea点击:

以下代码段描绘了各种方式,其中程序流可以在C#中重新路由,包括IF-ELSE结构,while循环,以及foreach循环。

if (i < 10)
{
  //go here if i is less than 10
}
else
{
  //go here otherwise
}
while(i < 10)
{
  //keep looping through here as long as i is less than 10
}
for(int i = 0; i < 10; i++)
{
    //loop 10 times
}
foreach(MyClass mc in myCollection)
{
  //... execute once for each mc object in myCollection
}