Click here to Skip to main content
15,559,682 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, as the topic above.. i wanna ask you, which one is the best for store data temporary in memory ?? :~ Give me your explanation, so i can find the best one for my project.. Thank you. :)

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();

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();         

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.
Share this answer
Teamsar Muliadi 1-Sep-10 5:35am    
Is there any other difference between these collections, i mean IDictionary is more faster than hashtable.. ??
To have an answer your question you need to think first about what kind of data you want to temporary store in memory, that is very important as hastable and arraylist are very diffrent from each other in how they store data and what kind of data they can store.
for example:

1)In an Arraylist We Can Add any datatype value,Every item in an
arraylist is treated as an object.

2)Hashtable is collection of key,value pairs
i)Key Can be any datatype
ii)Key Cannot be null refrrence
iii)but value can be null referrence
And don't forget that Hashtable implements IDictionary

3) IDictionary is an interface. you can implement it to create your own
collection which provides Key-pair structures.
Hashtable is an example.

performance wise Retrieving the data by key in a Hashtable is faster than retrieving it in an Arraylist.

I hope this helps
Share this answer
Teamsar Muliadi 2-Sep-10 0:23am    
Thank you helmy. :)
Each collection class is different and it's not possible to say which one is the best... And almost all of them store data temporarily in memmory.

Your choice depends on your needs. Do you need to build the collection dynamically? Do you need to save time or memory space? Do you need a sorted or unsorted collection? Does the collection need to be be read-only?

ps. No matter what you choose, do not use ArrayList...
Share this answer
Teamsar Muliadi 1-Sep-10 5:28am    
Mmmm... why did you say not to use ArrayList ?? Give me your reason, please.. :) so i can believe, that i should not use array list. And in my project, no matter how much memory will be used.. i want my application more faster than before. May you advice me, which one is the best for this situation..??
Kubajzz 1-Sep-10 5:37am    
The ArrayList class was introduced in early versions of .NET long before generics were added. List(T) is a newer generic class that provides pretty much the same functionality. The advantage is that List(T) is type safe, therefore brings better performance and decreases the probability of various bugs...

I think you will never ever need to use ArrayList unless you need to work with an old version of .NET (older than 2.0).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900