我是C#的新手,並試圖學習如何發送一個2D數組的單個行到一個函數。我有一個3行2列的二維數組。如果我想將第三行發送給名爲calculate
的函數,請告訴我如何執行此操作。發送一個二維數組的一行到c中的函數#
namespace test
{
class Program
{
static void Main(string[] args)
{
string[,] array2Db = new string[3, 2] { { "one", "two" }, { "three", "four" }, { "five", "six" } };
calculate(array2Db[2,0]); //I want to send only the 3rd row to this array
//This array may contain millions of words. Therefore, I can't pass each array value individually
}
void calculate(string[] words)
{
for (int i = 0; i < 2; i++)
{
Console.WriteLine(words);
}
}
}
}
任何幫助,將不勝感激
這是一個很好的例子,但與問題的例子相比。這可能很難理解。 –
@ Innat3感謝您舉例說明。當我運行這段代碼時,它給出了一個輸出如下:'System.String []' 'System.String []' –
@DP。啊我發現這個問題,你沒有在** calculate()**方法中顯示數組元素時傳遞索引值。我將添加更新 – Innat3