Actually,
IDictionary
is an interface, which is implemented by
Hashtable
. So, I guess you actually need a comparison between a
Hashtable
and a
ArrayList
.
Now, these two are different in nature.
An
ArrayList
can hold objects of any kind, and, requires no key. That is,
int a =10;
Person p = new Person();
ArrayList list = new ArrayList();
list.Add(a);
list.Add(p);
Whereas, a
HashTable
holds objects of
DictionaryEntry
only. A
DictionaryEntry
obejct has two fields, a
Key
and a
Value
.
That is,
Hashtable ht = new Hashtable();
ht.Add("key","value");
Later, you can retrieve the value from the
Hashtable
using the key as follows:
string value = (string)ht["key"];
Internally, after you store data inside the
Hashtable
, each entry becomes a
DictionaryEntry
So, if you need to store any data using Key/Value pair, you need to use
Hashtbale
, And, if you need to store only data without using any key, you can use
ArrayList
. It depends on your requirement, and, there is no question of best practices between these two.