我正在尝试创建一个C#应用程序来模拟客户在活动中使用的停车场。
到目前为止,我已经创建了一个int 3d数组,其中包含有关停车场的一些信息。我想要实现的是创建一个哈希表,它将有一个唯一的id作为键(客户的id )和3d数组作为值。
int[][][] myArray = new int[10][][];
... //Code that populates the 3d array
Hashtable ht = new Hashtable();
ht.Add(1, myArray[0][0][0]); // myArray[0][0][0] has the value of [3][5][7]
// When debugging the hashtable the key is 1 and value 1当我访问id为1的哈希表时,我期望的是3d数组,而不是当前返回的数字1。
如果我的要求不可行,请提出另一种基于唯一键访问3d数组的解决方案。提前谢谢你。
发布于 2019-04-21 05:15:29
而不是:
ht.Add(1, myArray[0][0][0]);...try:
ht.Add(1, myArray);但您应该首选Dictionary,因为它是强类型的,可以防止运行时错误。
var dict = new Dictionary<int, int[][][]>();https://stackoverflow.com/questions/55777594
复制相似问题