Thursday, August 26, 2010

Performance consideration using collection .Net framework


.Net framework is loaded with good amount of collection to make programming as easier, when we are developing small application it is ok if we don’t consider which

Programming practice is batter then other. But if we are working on any application having enterprise customers we must have to think about which programming element is batter over other. Here I have tried to make some flash over this.


1) Array:

·         Use strongly typed array if you don’t won’t much operations like searching and sorting.

·         Strongly Arrays gives best performance because they avoids boxing and unboxing.

2) Iteration:

·         Index based iteration will be efficient then enumerating (for each). Use loops for very big size collections.

3) Collections:

·         Prefer Array over Collection for storing Value types, this will avoid boxing and unboxing.

·         Use strongly typed collection, Use StringCollection for storing string instead of ArrayList.

·         Use binary search method while searching large size ArrayList.

·         Store small amount of data in ListDictionary instead of Hashtable.

·         Use StringDictionary for storing strings.

·         Avoid using SortedList if you are performing add/update operation frequently, use ArrayList instead.

·         If you are Using ArrayList declare it with approximate possible length, this will save memory, remember that doing this you will not lost variable length feature of ArrayList.(e.g. Use ArrayList arrList = new ArrayList(4);)


Any inputs will always be accepted.



Haresh Dhameliya.


  1. Hello Nirav and Haresh,

    Nice article.
    Keep it up.

    Lyra Belaqua :))

  2. The main objective of collections is to deal with a lot of items, and as the variety of items increases the efficiency of your program will be impacted. To decrease the impact of the variety of items on your program you have to choose the right kind of selection you will use.


Comments posted on ASP.Net Ajax Tutorials Blog are moderated and will be approved only if they are on-topic and not abusive. Please email me or my team for tech-support or blogging related questions. Avoid including website URLs in your comments - Thanks Author