{ 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...
// { 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...
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}
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}
// 你的需求不太明确,根据题目,貌似只需要知道数组长度就行了!
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));
}
// 三楼最后一个 select 可以省略掉
string result = string.Join(" ", arry.SelectMany(i => i).OrderBy(i => i).ToArray());
我那个不正确,我以为是顺序螺旋循环,但他里面的数字是断开的,所以必须全部取出来排序,然后拼接。
不可省略哦