This article is a mirror article of machine translation, please click here to jump to the original article.

View: 23209|Reply: 0

[Console Program] C# divides arrays into two groups, two in groups

[Copy link]
Posted on 1/12/2016 3:28:10 PM | | | |


This is a rendering, if you want 3 and, 4, or other groups, the writing method is similar to this

C# divides arrays into two groups, two in groups

Go straight to the source code

  1. List<string> list=new List<string>();
  2.             int[] intlist = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
  3.             for (int i = 0; i < intlist.Length; i++)
  4.             {
  5.                 if (i % 2 == 0)
  6.                 {
  7.                     if (i + 1 == intlist.Length)
  8.                     {
  9.                         list.Add(intlist[i].ToString());
  10.                     }
  11.                     else {
  12.                         list.Add(intlist[i].ToString() + ": :" + intlist[i + 1].ToString());
  13.                     }
  14.                     
  15.                 }
  16.             }

  17.             foreach (string str in list)
  18.             {
  19.                 Console.WriteLine(str);
  20.             }
Copy code








Previous:SendCloud Sohu C# version of the email sending tool
Next:Linux chmod command explained in detail
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com