我现在是这么写的
int[] arr1=arr[0];
for(int i=1; i<arr.GetLength(0); i++)
arr=arr.Concat(arr[i]).ToArray();
能不能不用循环?
这个简单
arr1 = arr.SelectMany(x => x).ToArray();
除了这种写法,还可以用Aggregate
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[][] arr = new int[][]
{
new int[] { 1, 2, 3 },
new int[] { 4, 5 },
new int[] { 6, 7 }
};
int[] query = arr.Aggregate(new int[] { }, (pre, curr) => pre.Concat(curr).ToArray());
foreach (var item in query)
Console.WriteLine(item);
}
}
}
LINQ是很灵活的,绝对不是说只有一个办法,我告诉你的只是解决办法之一。
建议你系统学学。
参考:http://msdn.microsoft.com/library/bb308959.aspx