日期:2014-05-17  浏览次数:20805 次

c#循环 像正方形一样一直循环
1 2 3 4
5     6
7 8 9 2

像这样1 2 3 4 6 2 9 8 7 5再5 1 2 3 4 6 2 9 8 7一直循环怎么写?
c# 循环

------解决方案--------------------
你把这几个数放数组或列表中,转就是了
------解决方案--------------------
不就是一个环么。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] data = { 1, 2, 3, 4, 6, 2, 9, 8, 7, 5 };
            for (int i = 0; i < data.Length; i++)
            {
                int pos = data.Length - i % data.Length;
                int[] current = data.Skip(pos).Take(data.Count() - pos).Concat(data.Take(pos)).ToArray();
                foreach (int x in current) Console.Write(x);
                Console.WriteLine();
            }
        }
    }
}


1234629875
5123462987
7512346298
8751234629
9875123462
2987512346
6298751234
4629875123
3462987512
2346298751
Press any key to continue . . .
------解决方案--------------------
用二维数组不停的循环就可以了。。。。
------解决方案--------------------

 static void Main(string[] args)
        {
            int[] data = { 1, 2, 3, 4, 6, 2, 9, 8, 7, 5 };
            for (int i = 0; i < data.Length; i++)
            {
                for (int j = 0; j < data.Length; j++)
                {
                    Console.Write(data[(data.Length - i + j) % data.Length]+"  ");
                }
              &