Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Key -> int & both values -> ulong,

How to initialize & fetch values of such dictionary. I am using VS-2005.

If i use a class or struct then how do i fetch the values.

like image 443
Royson Avatar asked Dec 04 '09 09:12

Royson


1 Answers

This would be an option:

Dictionary<int, KeyValuePair<ulong, ulong>> dictionary = new Dictionary<int, KeyValuePair<ulong, ulong>>();

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

dictionary.Add(1, new KeyValuePair<ulong, ulong>(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;
like image 177
naspinski Avatar answered Oct 21 '22 06:10

naspinski