.NET dictionary with two keys and one value

前端 未结 13 2961
盖世英雄少女心
盖世英雄少女心 2020-12-14 00:23

Is there a dictionary available in .NET that could hold 2 keys and one value. Like

Dictionary(Of TKey, Of TKey, TValue)

I have

13条回答
  •  一生所求
    2020-12-14 00:23

    As suggested in a comment to your question you could simply use an Object key for your Dictionary:

    Dictionary dict = new Dictionary();
    dict.Add("abc", 111);
    dict.Add(345, 111);
    

    To get a cleaner solution you could wrap this dictionary in a custom class and create your version of Add method:

    public void Add(ISet keys, T value){
        foreach(Object k in keys)
        {
            _privateDict.Add(k, value); 
        }
    }
    
        

    提交回复
    热议问题