The way to re-learn C # (i)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.