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

后端 未结 9 1155
悲&欢浪女
悲&欢浪女 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:14

    This would be an option:

    Dictionary> dictionary = new Dictionary>();
    

    If you want to add in a value: Key=1, Pair = {2,3}

    dictionary.Add(1, new KeyValuePair(2, 3));
    

    If you want to retrieve those values:

    var valuePair = dictionary[1];
    ulong value1 = valuePair.Key;
    ulong value2 = valuePair.Value;
    

    Or simply:

    ulong value1 = dictionary[1].Key;
    

提交回复
热议问题