From graduation to now also quite a long time, has been in the C # programming, but has long been engaged in business-related functions, technical aspects are not too strong, some things ambiguous grasp of the not firm, even the implementation of the way is a bit old, but it is necessary to learn again.
Return, break, continue are often used in the process of business process cycle, with the following functions:
static void Main (string[] args)
{
for (int i = 5; i > 0; i--)
{
if (i = = 1)
{
return;//directly to the end of this method, to 1 of the position
}
if (i = = 2)
{
break;//Direct End loop, to 2 position
}
if (i = = 3)
{
continue;//end Current, continue execution loop
}
Console.WriteLine (i);
}//2
Console.ReadLine ();
}//1
In the foreach loop, the function and for are consistent, and the efficiency and pros and cons of foreach and for are not compared, depending on the specific business scenario.
There is another way of looping in the daily process foreach , which only supports return, similar to the continue function of the For loop, Is the end of the current execution loop ps: Break is not supported and continue
List<int> intlist = new list<int> () { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; intlist.foreach (c => { if (c == 3) { return; } else { &nbsP; console.writeline ( "c=:" + c); } });
The way to re-learn C # (i)