/*
Author: Jiangong SUN
*/
I'll add 5 million numbers using ArrayList, List<object> and List<int>.
We will compare the time used for each iteration.
ArrayList resizes dynamically. As elements are added, it grows in capacity to accommodate them. It is most often used in older C# programs. It stores a collection of elements of type object. This makescastingnecessary.
Hashtable vs. Dictionnary
I'll add 10 millions numbers into HashTable and Dictionary<int, int>.
The time used for HashTable and Dictionary are:
Hashtable optimizes lookups. It computes a hash of each key you add. It then uses this hash code to look up the element very quickly. It is an older .NET Framework type. It is slower than the generic Dictionary type.
Read speed:
reference:
http://stackoverflow.com/questions/128636/net-data-structures-arraylist-list-hashtable-dictionary-sortedlist-sorted/128754#128754
http://stackoverflow.com/questions/11707344/hashtable-or-dictionary-which-one-is-better-and-why-when-should-each-be-used
http://stackoverflow.com/questions/3061182/when-to-use-a-hashtable