我正在尝试创建一个包含 char、int 和 int 的 bool 3d 数组,例如
Table['a', 0, 5] = false;
Table['b', 1, 4] = true;
我创建了 2d 但无法创建 3d
var cells = new bool[word.Length, word.Length];
for (int i = 0; i < word.Length; i++)
{
for (int j = 0; j < word.Length; j++)
{
cells[i, j] = false; // what to write here
}
}
最佳答案
您可以使用元组和 bool 值的字典,如下所示:
var t = new Dictionary<Tuple<char, int, int>, bool>();
t.Add(Tuple.Create<char, int, int>('a', 0, 5), false);
t.Add(Tuple.Create<char, int, int>('b', 1, 4), true);
// Prints false
Console.WriteLine("a, 0, 5 = {0}", t[Tuple.Create<char, int, int>('a', 0, 5)]);
// Prints true
Console.WriteLine("b, 1, 4 = {0}", t[Tuple.Create<char, int, int>('b', 1, 4)]);
关于c# - 如何在 C# 中创建一个由 char、int、int 组成的 bool 3D 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47166535/