我想寫填充多維矩形陣列的擴展方法。我知道如何與一個固定數量的測量做了數組:在C#中填充矩形陣列的擴展方法
public static void Fill<T>(this T[] source, T value)
{
for (int i = 0; i < source.Length; i++)
source[i] = value;
}
public static void Fill<T>(this T[,] source, T value)
{
for (int i = 0; i < source.GetLength(0); i++)
for (int j = 0; j < source.GetLength(1); j++)
source[i, j] = value;
}
public static void Fill<T>(this T[,,] source, T value)
{
for (int i = 0; i < source.GetLength(0); i++)
for (int j = 0; j < source.GetLength(1); j++)
for (int k = 0; k < source.GetLength(2); k++)
source[i, j, k] = value;
}
我可以寫一個填充方法爲所有多維矩形陣列?
你所有的例子都是矩形數組,而不是參差不齊的數組。你確定你想解決鋸齒陣列的問題嗎? – 2009-12-07 15:05:05
對不起,我在我的問題中犯了一個錯誤。已經修復 – AndreyAkinshin 2009-12-07 15:17:30