【发布时间】:2013-01-17 18:16:05
【问题描述】:
我希望有一个使用整数数组作为键的字典,如果整数数组具有相同的值(甚至不同的对象实例),它们将被视为相同的键。我该怎么做?
以下代码不起作用,因为b 是不同的对象实例。
int[] a = new int[] { 1, 2, 3 };
int[] b = new int[] { 1, 2, 3 };
Dictionary<int[], string> dic = new Dictionary<int[], string>();
dic.Add(a, "haha");
string output = dic[b];
【问题讨论】:
-
重复:stackoverflow.com/questions/3383534/… 有点与
List<int>有关