Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Selecting a Collection Class

Be sure to choose your Collections class carefully. Using the wrong collection can restrict your use of the collection.

Consider the following questions:

  • Do you need a sequential list where the element is typically discarded after its value is retrieved?
    • If yes, consider Queue or Stack.
    • If not, consider the other collections.
  • Do you need to access the elements in a certain order, such as first-in-first-out, last-in-first-out, or randomly?
    • Queue offers first-in-first-out access.
    • Stack offers last-in-first-out access.
    • The rest of the collections offer random access.
  • Do you need to access each element by index?
  • Will each element contain one value, a combination of one key and one value, or a combination of one key and multiple values?
  • Do you need to sort the elements differently from how they were entered?
    • Hashtable sorts the elements by the hash code of the key.
    • SortedList sorts the elements by the key, based on an IComparer implementation.
    • ArrayList provides a Sort method that takes an IComparer implementation as a parameter.
  • Do you need fast searches and retrieval of information?
    • ListDictionary is faster than Hashtable for small collections (10 items or less).
  • Do you need collections that accept only strings?
    • StringCollection (based on IList) and StringDictionary (based on IDictionary) are in the System.Collections.Specialized namespace.

See Also

Creating and Manipulating Collections | System.Collections Namespace | System.Collections.Specialized Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft