获取一个double [,]矩形阵列的双[]排阵 [英] Getting a double[] row array of a double[,] rectangular array

查看:104
本文介绍了获取一个double [,]矩形阵列的双[]排阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你有一个像数组:

double[,] rectArray = new double[10,3];

现在你想要的fouth行作为3个元素的双重[]数组没有这样做的:

Now you want the fouth row as a double[] array of 3 elements without doing:

double[] fourthRow = new double[]{rectArray[3,0],
                                  rectArray[3,1], 
                                  rectArray[3,2]};

是否有可能好歹?即使使用Marshal.Something方法?

Is it possible someway? Even using a Marshal.Something approach?

谢谢!

推荐答案

LINQ救援:

var s = rectArray.Cast<double>().Skip(9).Take(3).ToArray();

说明:铸造一多维数组变平并将它与单个二维数组。之后,我们需要做的就是跳到我们想要的元素(2-D数组中的第4个元素解析为跳过(9)...),并采取3个元素,从它)。

Explanation: Casting a multi-dimensional array flattens it to a single-dimensional array. After that all we need to do is skip to the element we want (the 4th element in the 2-D array resolves to Skip(9)...) and take 3 elements from it).

这篇关于获取一个double [,]矩形阵列的双[]排阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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