.NET dictionary with two keys and one value

前端 未结 13 3007
盖世英雄少女心
盖世英雄少女心 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:50

    If you are using C# 7.0 the best way to do this is to use tuple types and literals:

    // Declare
    var dict = new Dictionary<(string, long), long>();
    
    // Add
    dict.Add(("abc", 345), 111);
    
    // Get
    var searchedValue = dict[("abc", 345)];
    

提交回复
热议问题