转换二维数组数组

2023-09-02 21:10:35 作者:珎的借口让我心寒

什么是 selectMany.ToArray()的方法?它是一个内置的方法 C#

What is selectMany.ToArray() method? Is it a built in method in C#?

我需要二维数组转换为一维数组。

I need to convert two dimensional array to one dimensional array.

推荐答案

如果你的意思的锯齿的阵列( T [] [] ) ,的SelectMany 是你的朋友。但是,如果你的意思的矩形的阵列( T [,] ),那么你可以列举的日期数据通过的foreach - 或:

If you mean a jagged array (T[][]), SelectMany is your friend. If, however, you mean a rectangular array (T[,]), then you can just enumerate the date data via foreach - or:

    int[,] from = new int[,] {{1,2},{3,4},{5,6}};
    int[] to = from.Cast<int>().ToArray();