二维数组
- C# code
{ 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...
[解决办法]
- C# code
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}
[解决办法]
- C# code
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}
[解决办法]
- C# code
// 你的需求不太明确,根据题目,貌似只需要知道数组长度就行了!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));}
[解决办法]
[解决办法]
[解决办法]
- C# code
// 三楼最后一个 select 可以省略掉string result = string.Join(" ", arry.SelectMany(i => i).OrderBy(i => i).ToArray());