<ti***********@gmail.comwrote in message
news:11*********************@y66g2000hsf.googlegro ups.com...
Is there a typical way to create a dictionary (or hash table) with two
values, instead of one?
Currently, my data structure is TWO dictionaries, each with matching
and fully sychronized keys. This allows me to have one key with two
values (one value in each dictionary). This is ugly code as the
dictionaries could get out of synch (due to a bug or something).
Titan
As Jon suggested use an object with two properties. Here is a generic
version that you would use like:
DualValueDictionary<long, string, intd = new DualValueDictionary<long,
string, int>();
d.Add(123, "hello", 25);
if(d[123].Value1 == "hello") .....
public class DualValueDictionary<Tkey, V1, V2: Dictionary<Tkey,
DualValues<V1, V2>>
{
public void Add(Tkey key, V1 value1, V2 value2)
{
base.Add(key, new DualValues<V1,V2>(value1, value2));
}
}
public class DualValues<V1, V2>
{
public DualValues(V1 v1, V2 v2)
{
this.value1 = v1;
this.value2 = v2;
}
private V1 value1;
public V1 Value1
{
get
{
return this.value1;
}
}
private V2 value2;
public V2 Value2
{
get
{
return this.value2;
}
}
}
PS