0
我想從控制檯應用程序讀取值以將它們添加到二維數組。C#將項目添加到2維數組
當前代碼:
public void getUserResponses(int amount)
{
int current = 0;
string[,] userArray = new string[amount, 2]; // Array
while (current < amount)
{
Console.WriteLine("Please enter username #" + current);
string username = Console.ReadLine();
// Add username to array
current++;
}
}
正如你可以在代碼中看到,我想讀的用戶名,然後將其添加到陣列。
例子:
閱讀的用戶名
string username = Console.ReadLine();
然後將用戶名添加到陣列中的格式如下:
userArray[username][placeholder]
我怎麼能管理這個?
爲什麼你有第二維在你的數組? –
考慮使用數據結構和/或字典。 –
要添加兩個值到數組中,第二個尚未創建,但生病需要它以後。 – user7347727