快速的方式来二维阵列转换成一个列表(一维) [英] Fast way to convert a two dimensional array to a List ( one dimensional )

查看:160
本文介绍了快速的方式来二维阵列转换成一个列表(一维)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个维数组 - 我需要将其转换为一个列表(同一对象)

I have two dimensional array - and I need to convert it to one List ( same object )

我不希望与'对'或'的foreach循环,将采取每个元素,并把它添加到列表来做到这一点。

I don't want to do it with 'for' or 'foreach' loop that will take each element and add it to the List.

有一些其他的方式来做到这一点?

Is there some other way to do it ?

感谢

推荐答案

要转换双击[,] 列表<双> ?如果你正在寻找一个班轮,在这里不用

To Convert double[, ] to List<double> ? If you are looking for a one-liner, here goes

double[,] d = new double[,]
{
    {1.0, 2.0},
    {11.0, 22.0},
    {111.0, 222.0},
    {1111.0, 2222.0},
    {11111.0, 22222.0}
};
List<double> lst = d.Cast<double>().ToList()



但是,如果你正在寻找的东西有效,我宁愿说你不使用这个code。结果
请按照以下任一提到的两个答案。两者都实现得多更好的技术。


But, if you are looking for something efficient, I'd rather say you don't use this code.
Please follow either of the two answers mentioned below. Both are implementing much much better techniques.

这篇关于快速的方式来二维阵列转换成一个列表(一维)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆