System.Collections Namespace
Namespace Overview
The System.Collections
namespace contains interfaces and classes that define various collections of objects. These collections include lists, queues, stacks, hash tables, and dictionaries. This namespace also contains abstract base classes that you can derive from to create your own collections.
It is recommended to use the generic collection types in the System.Collections.Generic
namespace whenever possible, as they provide compile-time type checking and better performance.
Classes
ArrayList
Represents a strongly typed list of objects that can be accessed by index.
BitArray
Represents a compact representation of bits, where each element is a Boolean value.
CaseInsensitiveComparer
Implements
IComparer
and provides a case-insensitive comparison of objects.CaseInsensitiveHashCodeProvider
Provides a hash code provider that performs case-insensitive hashing.
CollectionBase
Provides a base class for implementing collections.
Comparer
Implements
IComparer
and provides a case-sensitive comparison of objects.DictionaryBase
Provides a base class for implementing a dictionary, or a collection of key/value pairs.
Hashtable
Represents a collection of key-value pairs that are organized based on the hash code of the key.
Queue
Represents a first-in, first-out (FIFO) collection of objects.
ReadOnlyCollectionBase
Provides a base class for implementing read-only collections.
SortedList
Represents a collection of key/value pairs that are sorted by key and are accessible by index.
Stack
Represents a last-in, first-out (LIFO) collection of objects.
Interfaces
ICollection
Represents a strongly typed collection of objects.
IComparer
Supports a comparison of a data type.
IDictionary
Represents a collection of key/value pairs that are accessible through a key or an index.
IEnumerable
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
IEnumerator
Supports a simple iteration over a collection.
IList
Represents a collection of objects that can be individually accessed by index.
IHashCodeProvider
Provides a hash code for an object.
Enumerations
CollectionChangedAction
Specifies the action that caused the collection to change.
Example Usage (ArrayList)
using System;
using System.Collections;
public class Example
{
public static void Main()
{
ArrayList myArrayList = new ArrayList();
myArrayList.Add("Hello");
myArrayList.Add("World");
myArrayList.Add(123);
foreach (object item in myArrayList)
{
Console.WriteLine(item);
}
}
}