Friday, May 16, 2008

When to use Arrays and Collections

A quick overview of when to use Arrays and Collections

Arrays :
When :You know the required array size at design time.

ArrayList:
When :You do not know the required array size at design time.

Hashtable:
When :To store Large amounts of data For example, product catalogues where a product ID is the key.

HybridDictionary:
When : For storing data when the number of records is expected to be low most of the time, with occasional increases in size. If you are sure that the size of collection will be always high or always low, you should choose Hashtable and ListDictionary respectively. This avoids the extra cost of the HybridDictionary, which acts as a wrapper around both these collections.

ListDictionary:
When :To store small amounts of data (fewer than 10 items)

NameValueCollection:
When : To store strings of key/value pairs in a pre-sorted order. Note that you can also have multiple entries with the same key.
for example:if you need to display subjects registered by students in a particular class because it can store the data in alphabetical order of student names.

Queue:
when :You need to access data sequentially, based on priority. For example, an application that scans the waiting list of plane

SortedList:
When :The collection can be used where the data is mostly static and only a few records need to be added or updated over a period of time, For Frequently updated data use ArrayList with Sort

Stack:
When: you need to process items in a last–in, first-out manner. For example, an application that needs to monitor the 10 most recent users visiting a Web site over a period of time.

StringCollection:
When : store string data that changes frequently and needs to be retrieved in large chunks.

StringDictionary:
When : store static string data needs to be retrieved in large chunks.

The above details I posted for getting a quick overview, Read this msdn article for detailed design guidelines

References:

No comments:

Post a Comment