如何从二维数组中随机选择一个位置?

1 c# random multidimensional-array

我目前正在开发一款控制台问答游戏,为此我需要从 2D 数组的随机类别中选择随机问题。但我不知道如何从二维数组中随机选择。

我无法显示完整的数组,因为它们非常大 - 下面是修剪后的版本:

string[,] mineKategorier = new string[10, 6]
{
    {"C#","Question one here", "Question two here", "Question three here"},
    {"Spil engines", "Question one here", "Question two here", "Question three here"},
    {"Sport", "Question one here", "Question two here", "Question three here"},
};
Run Code Online (Sandbox Code Playgroud)

Dmy*_*nko 5

Random rnd = new Random();
int row = rnd.Next(mineKategorier.GetLength(0));
int column = rnd.Next(mineKategorier.GetLength(1));

string randomKategori = mineKategorier[row, column];
Run Code Online (Sandbox Code Playgroud)