First, if both the source array you use, and the destination array you intend to copy to,
both have the same Rank (number of dimensions), and are of the same Type, and you want to copy a Row, or some number of Rows, then you can use the various 'Copy Methods in the Array Class: [
^].
Here's a general purpose generic function I've used in the past to get a copy of either a Row, or a Column (i.e., a one-dimensional Array result of the same Type value as the source array's values), of an Array from a two-dimension Array:
public T[] CopyRowOrColumn<T>(int ndx, T[,] sourceAry, bool isrow = true)
{
T[] resultAry;
int rank = sourceAry.Rank;
if(sourceAry == null || rank != 2) throw new ArgumentException("requires a two-dimensional array as input that contains values");
int rowdim = sourceAry.GetLength(0);
int coldim = sourceAry.GetLength(1);
if (isrow)
{
if(ndx > rowdim) throw new ArgumentException("index greater than row dimension");
resultAry = new T[coldim];;
}
else
{
if(ndx > coldim) throw new ArgumentException("index greater than column dimension");
resultAry = new T[rowdim];
}
T value;
for (int row = 0; row < rowdim; row++)
{
for (int col = 0; col < coldim; col++)
{
value = sourceAry[row, col];
if (isrow && row == ndx)
{
resultAry[col] = value;
}
else if(col == ndx)
{
resultAry[row] = value;
}
}
}
return resultAry;
}
Usage sample:
var testrow = CopyRowOrColumn<double>(2, dblAry, true);
var testcol = CopyRowOrColumn<double>(2, dblAry, false)
I am going to assume you can use this, and easily adapt it to insert the values you copy from the source Array into your destination Array.
Good things to understand in theory, and practice, about Arrays:
1. often you can avoid a lot of "grunt" work by using generic Lists instead.
2. Array.Rank: the number of dimensions of an Array
3. the 'Array.GetLength method that returns the size of a specific Array dimension