VikasGoyal

What is the equivalent of java hashmap in Csharp

http://DotNetWithMe.blogspot.com
vikas goyal




Re: Visual C# Language Java HashMap in CSharp

Mike Danes

The closest one is System.Collections.Hashtable:

http://msdn2.microsoft.com/en-us/library/system.collections.hashtable.aspx

If you are using .NET 2.0 you can also try using the generic dictionary System.Collections.Generic.Dictionary<TKey, TValue>:

http://msdn2.microsoft.com/en-us/library/xfhwa508.aspx





Re: Visual C# Language Java HashMap in CSharp

VikasGoyal

Java has both HashTable and HashMap. I believe both are same except that HashMap is not synchronized which makes it more performant.

do we have such collection available in CSharp

vikas






Re: Visual C# Language Java HashMap in CSharp

Mike Danes

None of the .NET Framework collections are synchronized by default.

In the case of Hashtable you can get a synchronized wrapper of an existing hashtable by using Hashtable.Synchronized method:

Hashtable syncHashtable = Hashtable.Synchronized(nonSyncHashtable);

or you can use the SyncRoot property to synchronize using a lock statement

lock (nonSyncHashTable.SyncRoot)

{

...

}