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
- List<string> list=new List<string>();
- int[] intlist = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
- for (int i = 0; i < intlist.Length; i++)
- {
- if (i % 2 == 0)
- {
- if (i + 1 == intlist.Length)
- {
- list.Add(intlist[i].ToString());
- }
- else {
- list.Add(intlist[i].ToString() + ": :" + intlist[i + 1].ToString());
- }
-
- }
- }
- foreach (string str in list)
- {
- Console.WriteLine(str);
- }
Copy code
|