.NET interview question :- Who is faster hashtable or dictionary ?

 Posted by articlesmaint on 3/1/2011 | Category: .NET Framework Interview questions | Views: 11295


This is again a typical collection .NET interview question. Dictionary is faster than hashtable as dictionary is a generic strong type. Hashtable is slower as it takes object as data type which leads to boxing and unboxing.


Below goes the same code for hashtable and dictionary.


 

Hashtable hashtable = new Hashtable();
hashtable[1] =
"One";
hashtable[2] = "Two";
hashtable[13] = "Thirteen";


 

var dictionary = new Dictionary<string,
int>();
dictionary.Add(i.ToString("00000"),
10);
dictionary.Add(i.ToString("00000"), 11);


 


Regards,




Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Vinay13mar on: 10/27/2012

Login to post response