我有一个典型的多维数组,但我需要为每个子数组添加一个键。像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>>>>()
? 谢谢。
_these括号:“()”_是可选的。 –