Java HashMap equivalent in C# is HashTable.
But in java the HashMap can have a null key ie key is a null reference and there can be duplicate keys ie basically keys with the same name.
I want a class that provides the above feature ie
1)stores in key value pairs
2) key can be null
3)Keys with the same name can be added.
or if there is another util class that provides the above mentioned features.
Please help me with this.
Thanks a lot in advance

Urgent help required--C# equivalent to Java HashMap
Timpie
SKCM
http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpref/html/frlrfsystemcollectionsicollectionclasstopic.asp
ChadLee
As for supporting a null key - you could implement your own IDictionary which allows this, using a Hashtable for everything other than the null key.
Jon
Dhanasu
Anyway, unfortunately there isn't a plain Dictionary<> class in PowerCollections, presumably because there's already one in the standard libraries. Alas, the standard one doesn't allow null keys (as we already discussed), so we can't use that...
Using a MultiDictionary<> to store single key/value pairs seems a little overkill, but perhaps it'll work.
SUPAXE
Get it at http://www.wintellect.com/powercollections
I can't speak too highly of that library!
For what you want, you'd use a "MultiDictionary". The code goes like this:
Wintellect.PowerCollections.MultiDictionary<string, string> test =
new Wintellect.PowerCollections.MultiDictionary<string, string>(true);
test.Add(null, "Null Test1");
test.Add(null, "Null Test2");
test.Add("Key", "Key Test1");
test.Add("Key", "Key Test2");
ICollection<string> null_key_values = test[null];
foreach (string s in null_key_values)
MessageBox.Show(s, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
ICollection<string> key_values = test["Key"];
foreach (string s in key_values)
MessageBox.Show(s, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
Kent Chenery
Data
MySchool StudentID Key Value
West College 10 Name Ricky
West College 10 Surmane Martin
West College 10 Adress DownStreet
West College 10 Zip 555
West College 20 Name Sharone
West College 20 Surmane Stone
West College 20 Adress 5th Ave.
West College 20 Zip 444
East College 30 Name Marry
East College 30 Surmane Christmas
East College 30 Adress UpStreet
East College 30 Zip 111
_____________________________
HashTable Structure
myHashTable [ MySchool, HashTable2]
myHasTable2 [ StudentID,HashTable3]
myHashTable3 [Key,Value]
___________________________
CODE
IDictionaryEnumerator
listEnumerator = myHastable.GetEnumerator(); while (listEnumerator.MoveNext()){
Response.Write(listEnumerator.Key.ToString());
Response.Write(
"--->");Response.Write(listEnumerator.Value.ToString());
Response.Write("<br>");
}
___________________________________________
OutPut
West College ---> System.Collections.Hashtable
East College ---> System.Collections.Hashtable
____________________________________________
Question / BrainStorming
How inner hashtable datas can be retrieved into a GridView
( That is the difference Java HashMap vs to C# HashTables.)
SHELMAN
However, it looks like the Power Collections support null keys, so it solves that problem neatly.
Jon