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#循环

解决方案 »

  1.   

    不就是一个环么。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 . . .
      

  2.   


     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]+"  ");
                    }
                    Console.WriteLine();
                }
                Console.ReadLine();
            }