how to initialize dictionary as (key,value,value) pair in C#

后端 未结 9 1153
悲&欢浪女
悲&欢浪女 2020-12-31 11:37

I want to store values as key,value,value pair. My data is of type

Key -> int & both values -> ulong,

How to initialize & fet

9条回答
  •  抹茶落季
    2020-12-31 12:29

    I'm not sure I understand your question correctly, but if you want to store more than one value in the value part of Dictionary, you could do something like this:

    var dic = new Dictionary>();
    

    You can use insert into the dictionary like this:

    dic.Add(42, new KeyValuePair(42, 42));
    dic.Add(43, new KeyValuePair(43, 43));
    

    And fetch the values like so:

    foreach (var a in dic)
    {
        Console.WriteLine("Key: {0}, Value1: {1}, Value2: {2}",
            a.Key, a.Value.Key, a.Value.Value);
    }
    

提交回复
热议问题