0
我有一個2維數組,我想在方法中返回數組的一行的引用,以便對該行的任何更改都會反映出來在原始數組中。現在我有下面的方法,但是它正在返回值的新實例,因爲傳遞的是雙精度值。如何返回一個雙行的引用[,]
public double[] GetRowReference(int rowNumber)
{
double[] output = new double[_allPoints.GetLength(1)];
for (int i = 0; i < _allPoints.GetLength(1); i++)
{
output[i] = _allPoints[rowNumber, i];
}
return output;
}
如何返回此行作爲參考而不是值?
這是不可能的。 (不幸的是)你最好尋找另一種方式,例如爲什麼不直接使用2d數組? –
另一種方法是使用鋸齒陣列,因此您可以返回內部數組的引用,但您必須更改程序的一部分。 'double [] [] array = new double [2] []; double [] reference = new [] {4d,4,5};數組[1] =參考;參考[1] = 6;' –
@ M.kazemAkhgary我想寫我的API,以便更容易理解行的含義,因此引用整個2d數組中給定行的屬性。我曾考慮過實現鋸齒狀數組,但是我認爲我錯過了2d數組實現。 – PlTaylor