If you are trying to group values together, this can be a great opportunity to create a simple structure or class and use it as a value in a dictionary.
public struct MyValue { public object Value1; public double Value2; }
then you can have your dictionary
var dict = new Dictionary<int, MyValue>();
you can even go further and implement your own dictionary class, which will handle any special operations that you need. for example, if you want to have an Add method that accepts int, object and double
public class MyDictionary : Dictionary<int, MyValue> { public void Add(int key, object value1, double value2) { MyValue val; val.Value1 = value1; val.Value2 = value2; this.Add(key, val); } }
then you can just create an instance and add it to the dictionary like this, and you don’t have to worry about creating MyValue structures:
var dict = new MyDictionary(); dict.Add(1, new Object(), 2.22);
Jon Erickson Feb 20 '09 at 16:31 2009-02-20 16:31
source share