日期:2014-05-17  浏览次数:21028 次

关于 multi dictionary?
泛型 Dictionary<(Of <(TKey, TValue>)>) 是一个key,相应的值。。

请问,存在 多个 key的用什么实现?
有没有 Dictionary 存在多个 key的 请教?

例子:
原来的Dictionary 是这样。。。
Dictionary<string, string> openWith = 
    new Dictionary<string, string>();

openWith.Add("1", "100");
openWith.Add("2", "200");


我现在想做的是。。

openWith.Add("1","0" "100");
openWith.Add("1","1" "150");
openWith.Add("1","2" "250");

openWith.Add("2","4" "500");
openWith.Add("2","8" "700");


然后 以下面形式读取数据。。。
foreach (KeyValuePair<string, Dictionary<string, string>> keys in openWith)
{
}
dictionary

------解决方案--------------------
蛋疼


public class CustomDictionary : Dictionary<string, Dictionary<string, string>>
{
    public void Add(string key, string subkey, string value)
    {
         Dictionary<string, string> entry;
         if(!base.TryGetValue(key))
         {
              entry = new Dictionary<string, string>();
              base.Add(key, entry);
         }
         entry[subkey] = value;
    }
}





------解决方案--------------------
傻,
Dictionary<string, List<string>>
就可以了。相同key的放在一个List里面
------解决方案--------------------
Dictionary<string, List<Cls>> openWith = 
    new Dictionary<string, List<Cls>>();

public class Cls
{
public string id;
pulic string value;

}
------解决方案--------------------
每次添加记录前:
if (!dict.ContainsKey("某key"))
    dict.Add("某key", new List<string>());
dict["某key"].Add("某值");

3个的话可以用Dictionary<string, Dictionary<string, List<string>>>
当然,我觉得你用DataTable更好。
------解决方案--------------------
public class Key
{
     public string FirstKey{get;set;}
     public string SecondKey{get;set;}

     public override bool Equals(object another){}
}

Dictionary<Key,string>