다음을 통해 공유


Commonly Used Collection Types 

Collection types are the common variations of data collections, such as hash tables, queues, stacks, dictionaries, and lists.

Collections are based on the ICollection interface, the IList interface, the IDictionary interface, or their generic counterparts. The IList interface and the IDictionary interface are both derived from the ICollection interface; therefore, all collections are based on the ICollection interface either directly or indirectly. In collections based on the IList interface (such as Array, ArrayList, or List) or directly on the ICollection interface (such as Queue, Stack, or LinkedList), every element contains only a value. In collections based on the IDictionary interface (such as the Hashtable and SortedList classes, or the Dictionary and SortedList generic classes), every element contains both a key and a value. The KeyedCollection class is unique because it is a list of values with keys embedded within the values, and, therefore, it behaves like a list and like a dictionary.

Generic collections are the best solution to strong typing. However, if your language does not support generics, the System.Collections namespace includes base collections, such as CollectionBase, ReadOnlyCollectionBase, and DictionaryBase, which are abstract base classes that can be extended to create collection classes that are strongly typed.

Collections can vary, depending on how the elements are stored, how they are sorted, how searches are performed, and how comparisons are made. The Queue class and the Queue generic class provide first-in-first-out lists, while the Stack class and the Stack generic class provide last-in-first-out lists. The SortedList class and the SortedList generic class provide sorted versions of the Hashtable class and the Dictionary generic class. The elements of a Hashtable or a Dictionary are accessible only by the key of the element, but the elements of a SortedList or a KeyedCollection are accessible either by the key or by the index of the element. The indexes in all collections are zero-based, except Array, which allows arrays that are not zero-based.

In This Section

Reference

  • System.Collections
    Provides reference documentation for the System.Collections namespace, which contains interfaces and classes that define various collections of objects.
  • System.Collections.Generic
    Provides reference documentation for the System.Collections.Generic namespace, which contains interfaces and classes that define generic collections.
  • ICollection
    Describes the major features of the ICollection class, which defines size, enumerators and synchronization methods for all nongeneric collections.
  • ICollection
    Describes the major features of the ICollection class, which defines methods to manipulate generic collections.
  • IList
    Describes the major features of the IList class, which represents a nongeneric collection of objects that can be individually accessed by index.
  • IList
    Describes the major features of the IList class, which represents a collection of objects that can be individually accessed by index.
  • IDictionary
    Describes the major features of the IDictionary class, which represents a nongeneric collection of key/value pairs.
  • IDictionary
    Describes the major features of the IDictionary class, which represents a generic collection of key/value pairs.
  • Collections and Data Structures
    Discusses the various collection types available in the .NET Framework, including stacks, queues, lists, arrays, and structs.
  • Generics in the .NET Framework
    Describes the generics feature, including the generic collections, delegates, and interfaces provided by the .NET Framework. Provides links to feature documentation for C#, Visual Basic, and Visual C++, and to supporting technologies such as reflection.