字典有重复键字典

2023-09-07 04:28:03 作者:成行的相思树郁郁葱葱

可能重复:   Is有替代字典/排序列表,允许重复?

我要寻找一个字典排序类的,可以有重复的钥匙。

I am looking for a Dictionary sort of class which can have duplicate Keys.

我搜索一下,发现的查找类可以用来存储重复键,但是它没有默认构造函数,因此,没有任何其他对象来查找我们不能对其进行初始化。

I search about it, and found LookUp class can use to store duplicate keys, but It has no default constructor, So we can't initialize it without any other object to LookUp.

但我一开始没有任何这样的对象从中我可以初始化一个Lookup对象。

But I have no any such object initially from which I can initialize a LookUp object.

所以,我的问题是,是否有任何类在.NET Framework 3.5的,其行为类似于字典,但让我有重复的按键,例如查找?

So, My question is, Is there any class in .Net framework 3.5, which behave like Dictionary but allow me to have duplicate keys like LookUp?

推荐答案

一个字典,根据定义,将永远无法拥有多个密钥。 (如果你抬头看任何会返回一个关键?)即使是查找,你是指,不允许它。你的什么可以的要做的就是让每个按键对应的多个值的(逻辑上,而不是技术上的)。这是通过具有词典中,它的数值是某种类型的数据结构进行(例如,一个列表),它包含所有对应于该特定键的值的

A Dictionary, by definition, will never be able to have multiple keys. (If you looked up a key whatever would you return?) Even a Lookup, which you refer to, doesn't allow it. What you can do is have each key refer to multiple values (logically, not technically). This is done by having a dictionary in which the value is a data structure of some sort (for example, a List) that contains all of the values that correspond to that particular key.