c# - 将锯齿状数组转换为列表

标签 c# arrays list multidimensional-array jagged-arrays

我有一个锯齿状的数组,我想将其转换为一个简单的列表。

int[][] jaggedArray = new int[][] 
{
    new int[] {1,3,5,7,9},
    new int[] {0,2,4,6},
    new int[] {11,22}
};

我想转换成列表

List<int> list = ?????

Fast way to convert a two dimensional array to a List ( one dimensional )

这道题将二维数组转换为列表,但对于锯齿状数组则失败了。

最佳答案

你可能会这样做:

List<int> list = jaggedArray.SelectMany(T => T).ToList();

关于c# - 将锯齿状数组转换为列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18783884/

相关文章:

list - 如何在Prolog中检查一个列表的所有元素是否都是另一个列表的成员

c# - 重复遍历列表

C# 泛型 : Can I constrain to a set of classes that don't implement an interface?

c# - 以编程方式将访问控制列表 (ACL) 权限分配给 'this folder, subfolders and files'

c++ - 在 C++ 中查找非元音对

python - 与使用两个 Numpy 数组进行矢量化相比,为什么使用 Numpy 数组和 int 进行算术运算时减法更快?

c# - 将 List<T> 转换为数组(多维)

c# - 当应用程序是 64 位时,以 32 位模式运行代码,可能吗?

c# - 如何使用 API 和 C# 向 telegram 发送消息?

arrays - 通过添加 JSonObject 创建 JsonArray