我有一个典型的多维数组,但我需要为每个子数组添加一个键之类的东西。像 JSON。
一个示例结构:
{
"0":
{
"1":
{
{1, 5, 9, 55}
},
"5":
{
{97, 82, 5}
}
},
"2":
{
"0":
{
{9}
},
"2":
{
{3, 2, 2, 1, 4}
}
},
"10":
{
"6":
{
{9, 10}
},
"7":
{
{0, 8, 2}
}
}
}
我将尝试用一个例子来解释它:
variable[0] would be equal "0"
variable[1] would be equal "2"
variable[3] would be equal "10"
variable[0][0] would be equal "1"
variable[0][1] would be equal "5"
variable[1][0] would be equal "0"
variable[1][1] would be equal "2"
variable[0][0][0] would be equal "1"
variable[0][0][1] would be equal "5"
variable[0][0][2] would be equal "9"
variable[0][0][3] would be equal "55"
variable[0][1][0] would be equal "97"
variable[0][1][1] would be equal "82"
variable[0][1][2] would be equal "5"
我可以通过使用更多变量来做到这一点,但我有很多数据可能需要在未来更改,所以我需要它们的结构类似于上面。在 C# 中执行此操作的最有效解决方案是什么?
我尝试了多维字典,但它的语法错误:
Dictionary<byte, Dictionary<byte, Dictionary<byte, Dictionary<byte, string>>>> scope = new Dictionary<byte, Dictionary<byte, Dictionary<byte, Dictionary<byte, string>>>>()
{
{
0,
{
1,
{
1,
{
1, "test"
}
}
}
}
};
textBox1.Text = scope[0][0][0][0];
那里有什么问题?
还有一个问题。做这些括号:“()”属于这个的末尾:
Dictionary<byte, Dictionary<byte, Dictionary<byte, Dictionary<byte, string>>>> scope = new Dictionary<byte, Dictionary<byte, Dictionary<byte, Dictionary<byte, string>>>>()
?