把{{1,2},{3,4}} 展开变成{1,2,3,4}
/// <summary>
/// 把一个2D数组展开成1d
/// </summary>
/// <param name="array2d">2d array</param>
/// <returns></returns>
static T[] Flatten2d<T>(this T[,] array2d)
{
var rowNum = array2d.GetLength(0);//行数
var colNum = array2d.GetLength(1);//列数
List<T> rtn = new List<T>();//todo 改进,此处开辟成Array,可能更快
for (int i = 0; i < rowNum; i++)
{
for (int j = 0; j < colNum; j++)
{
rtn.Add(array2d[i, j]);
}
}
return rtn.ToArray();
}