Royson Royson - 1 year ago 120
C# Question

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.

Answer Source

Create a structure to store your values:

struct ValuePair
    public ulong Value1;
    public ulong Value2;

Dictionary initialization:

Dictionary<int, ValuePair> dictionary = new Dictionary<int, ValuePair>();

Maybe List is enough, if you use int as key?


List<ValuePair> list = new List<ValuePair>();

ValuePair can be added to the list as following:

list.Add(new ValuePair { Value1 = 1, Value2 = 2 });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download