Numerous collections exist and at first glance some seem just as good as others, but you need to carefully
consider the use of the collection to ensure optimal performance. The following list describes the
collections and what their best uses are:
❑ The ArrayList dynamically resizes as items are added and is best used to store custom object
types when the data changes frequently—for example, when you are performing frequent
inserts and deletes.
❑ The HashTable is a collection of pairs of data (a key and a value) and is best suited for data that
doesn’t change frequently. It is especially useful for data that is queried often.
❑ The ListDictionary should only be used to store small amounts of data, generally fewer than
10 items.
❑ The NamevalueCollection is a sorted collection of keys and values and is best for data that is
already sorted. It is efficient for data that frequently changes or needs to be queried often.
❑ The Queue provides first-in, first-out storage, so it should be used when sequentially ordered
data is required.
❑ The SortedList stores keys and values in a sorted order. This makes adding data slow, because
existing items need to be rearranged to ensure the new item is in the correct order. ASortedList
is best for data that doesn’t change often.
❑ The Stack provides first-in, first-out storage, so it should be used when sequentially ordered
data is required.
❑ The StringCollection is a strongly typed ArrayList, so it is useful for storing strings in an
arbitrary order, and for strings that change frequently.
❑ The StringDictionary is a strongly typed HashTable, so it is useful when strings need to be
stored and those strings don’t change often.
posted on 2007-07-06 16:26  Atlantis  阅读(152)  评论(0编辑  收藏  举报