Home All Groups Group Topic Archive Search About
Author
1 Feb 2007 4:43 PM
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.

Author
1 Feb 2007 7:27 PM
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
Author
1 Feb 2007 7:56 PM
Brian Gideon
Show quote
On Feb 1, 10:43 am, "aryan" <aryanbit***@gmail.com> wrote:
> 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
Author
1 Feb 2007 10:05 PM
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.

--
Regards,
Robson Siqueira
Enterprise Architect
Show quote
"aryan" <aryanbit***@gmail.com> wrote in message
news:1170348203.990977.226150@h3g2000cwc.googlegroups.com...
> 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.
>
Author
3 Feb 2007 9:55 AM
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);
                    }
                }
            }

        }
    }
}

AddThis Social Bookmark Button