Hashtable MultiMap

  • Thread starter Thread starter aryan
  • Start date Start date
A

aryan

Hi,

I hope someone can help me with the following prob..

I need to implement a hashtable (or a dictionary) whose KEYs are
strings and VLAUEs are
again hashtables.
ie key - is a string and value -is another hashtable .
I want to implement it in C# .net but dont know the proper syntax to
start with. Is it possible with C# 2.0 generics?

Please help.

Thanks & regards ,

aryan.
 
Hello Aryan,

What's wrong with custom collection?!
Start from there http://www.ondotnet.com/pub/a/dotnet/2003/09/02/ilist.html
or see Power Collection for .NET http://www.wintellect.com/PowerCollections.aspx


A> hope someone can help me with the following prob..
A> I need to implement a hashtable (or a dictionary) whose KEYs are
A> strings and VLAUEs are
A> again hashtables.
A> ie key - is a string and value -is another hashtable .
A> I want to implement it in C# .net but dont know the proper syntax to
A> start with. Is it possible with C# 2.0 generics?
A> Please help.
A> Thanks & regards ,
A> aryan.
---
WBR, Michael Nemtsev [C# MVP] blog: http://spaces.live.com/laflour
team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
 
Hi,

I hope someone can help me with the following prob..

I need to implement a hashtable (or a dictionary) whose KEYs are
strings and VLAUEs are
again hashtables.
ie key - is a string and value -is another hashtable .
I want to implement it in C# .net but dont know the proper syntax to
start with. Is it possible with C# 2.0 generics?

Please help.

Thanks & regards ,

aryan.

Aryan,

What about Dictionary<string, Dictionary<TKey, TValue>> where TKey and
TValue are types you choose for the stored Dictionary.

Brian
 
I would go Dictionary, rather than Hashtable only. You could use only
hashtable for that, since the hashtable stores any type of object as value.
But with Dictionary, you stop that boxing/unboxing thing.
 
Thanks ebery one for your help .... i have tried it...

n here it goes....


//********************
namespace DictionaryDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Dictionary<string, Dictionary<string, string>> dict =
new Dictionary<string, Dictionary<string, string>>();

dict.Add("Key", new Dictionary<string, string>());
dict["BaseKey"].Add("SubKey", "Value");

foreach (KeyValuePair<string, Dictionary<string, string>>
entry in dict)
{
listBox1.Items.Add(entry.Key);
foreach (KeyValuePair<string, string> subEntry in
dict[entry.Key])
{
listBox2.Items.Add(subEntry.Key);
foreach (string str in dict[entry.Key].Values)
{
listBox2.Items.Add(str);
}
}
}

}
}
}
 
Back
Top