我希望将多维数组中的特定行复制到一个新的一维数组中,该数组可以在代码中的其他地方使用。
输入:
多维数组3,3
33 300 500,
56 354 516,
65 654 489,所需产出:
一维阵列(第二线)
56 354 516发布于 2016-01-25 06:28:50
var source = new int[3, 3]
{
{ 33, 300, 500 },
{ 56, 354, 516 },
{ 65, 654, 489 }
};
// initialize destination array with expected length
var dest = new int[source.GetLength(1)];
// define row number
var rowNumber = 1;
// copy elemements to destination array
for (int i = 0; i < source.GetLength(1); i++)
{
dest[i] = (int) source.GetValue(rowNumber, i);
}https://stackoverflow.com/questions/34986250
复制相似问题