{ 1,  2,  3,  4,  5,  6  },
// { 18, 19, 20, 21, 22, 7 },
// { 17, 28, 29, 30, 31, 8 },
// { 16, 27, 26, 25, 24, 9 },
// { 15, 14, 13, 12, 11, 10 }输出成 12345678910 11 12 13 14 15 16 17 18 19...

解决方案 »

  1.   


    void Main()
    {
    int[][] arry=new int[][]{ new int[]{ 1,  2,  3,  4,  5,  6  },
    new int[]{ 18, 19, 20, 21, 22, 7 },
    new int[]{ 17, 28, 29, 30, 31, 8 },
    new int[]{ 16, 27, 26, 25, 24, 9 },
    new int[]{ 15, 14, 13, 12, 11, 10 }};  string result=string.Join(" ",arry.SelectMany(i=>i).OrderBy(i=>i).Select(i=>i.ToString()).ToArray());
    Console.WriteLine(result);
    //1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 24 25 26 27 28 29 30 31}
      

  2.   


    void Main()
    {
    int[][] arry=new int[][]{ new int[]{ 1,  2,  3,  4,  5,  6  },
    new int[]{ 18, 19, 20, 21, 22, 7 },
    new int[]{ 17, 28, 29, 30, 31, 8 },
    new int[]{ 16, 27, 26, 25, 24, 9 },
    new int[]{ 15, 14, 13, 12, 11, 10 }};  string result=string.Join(" ",arry.SelectMany(i=>i).OrderBy(i=>i).Select(i=>i.ToString()).ToArray());
    Console.WriteLine(result);
    //1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 24 25 26 27 28 29 30 31}
      

  3.   


    // 你的需求不太明确,根据题目,貌似只需要知道数组长度就行了!
    public static void PrintLines(int[][] arr)
    {
        string s = "";
        Parallel.For(1, arr.GetLength(0) * arr.GetLength(1), x => s += x.ToString() + (x < 10 ? "" : " "));
        Console.WriteLine(s.Remove(s.Length - 1));
    }
      

  4.   


    // 三楼最后一个 select 可以省略掉
    string result = string.Join(" ", arry.SelectMany(i => i).OrderBy(i => i).ToArray());
    我那个不正确,我以为是顺序螺旋循环,但他里面的数字是断开的,所以必须全部取出来排序,然后拼接。
      

  5.   

    最后一个select 是将int[]转化成string[]
    不可省略哦
      

  6.   

    不知道前辈可否告知一些学习linq的方法或者资料 不是我问的小白 SQL用多之后 感觉思维有点难以转变