Hashtable MultiMap

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.
 
M

Michael Nemtsev

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
 
B

Brian Gideon

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
 
R

Robson Siqueira

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.
 
A

aryan

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);
}
}
}

}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top