且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将二维数组转换为列表(一维)的快速方法

更新时间:2023-02-27 07:56:42

double[,] 转换为 List,如果你正在寻找一个-班轮,来了

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();


但是,如果您正在寻找有效的东西,我宁愿说您不要使用此代码.
请遵循下面提到的两个答案之一.两者都在实施更好的技术.


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.