多键字典,其中只需要1个键来检索对象

Ton*_*Nam 2 c# collections dictionary hashtable data-structures

互联网上有几个地方谈论有多键密钥字典,如:

c#中的多键字典?

要么

C#中的多键词典(另一种)?

我正在寻找一个多键字典,只要我只提供一个键,就可以检索我正在寻找的对象.换句话说,如果我在哪里:

 // multyKeyDictionary = instance of a multikeydictionary 
 multyKeyDictionary.add(key1, key2, someObject);
Run Code Online (Sandbox Code Playgroud)

那么我希望能够将someObject作为:

multyKeyDictionary[key1]; 要么 multyKeyDictionary[key2];

Zde*_*pič 7

好吧,我不明白为什么你不使用常规字典并用不同的键添加对象两次.

Dictionary<string, object> dict = new Dictionary<string, object>();
dict.Add("key1", obj);
dict.Add("key2", obj);

// dict["key1"] == dict["key2"]
Run Code Online (Sandbox Code Playgroud)