System.Collections Namespace

Provides interfaces and classes that define various collections of objects, such as lists, queues, dictionaries, sets, and stacks. This namespace contains types that are not generic. For the generic equivalents, see the System.Collections.Generic namespace.

Interfaces

ICollection

Represents a collection of objects of a type that can be individually accessed by index.

Members

  • IsSynchronized (property)
  • Count (property)
  • SyncRoot (property)
  • Add(object value) (method)
  • Clear() (method)
  • CopyTo(Array array, int index) (method)
  • GetEnumerator() (method)
  • Remove(object value) (method)

IEnumerable

Exposes the enumerator, which supports a simple iteration over a collection of a non-generic type.

Members

  • GetEnumerator() (method)

IEnumerator

Supports a simple iteration over a collection of a non-generic type.

Members

  • Current (property)
  • MoveNext() (method)
  • Reset() (method)

IList

Represents a collection of objects that can be individually accessed by index.

Members

  • IsFixedSize (property)
  • IsReadOnly (property)
  • this[int index] (indexer)
  • Add(object value) (method)
  • Clear() (method)
  • Contains(object value) (method)
  • IndexOf(object value) (method)
  • Insert(int index, object value) (method)
  • Remove(object value) (method)
  • RemoveAt(int index) (method)

Classes

ArrayList

Represents a strongly typed list of objects that can be accessed by index. Provides methods for creating, searching and sorting lists.

public class ArrayList : IList, ICollection, IEnumerable

Members

  • Capacity (property)
  • Count (property)
  • IsFixedSize (property)
  • IsReadOnly (property)
  • IsSynchronized (property)
  • Item[int index] (indexer)
  • SyncRoot (property)
  • Add(object value) (method)
  • AddRange(ICollection c) (method)
  • BinarySearch(object value) (method)
  • Clear() (method)
  • Contains(object value) (method)
  • CopyTo(Array array) (method)
  • CopyTo(Array array, int index) (method)
  • Equals(object obj) (method)
  • GetEnumerator() (method)
  • GetRange(int index, int count) (method)
  • IndexOf(object value) (method)
  • IndexOf(object value, int startIndex) (method)
  • Insert(int index, object value) (method)
  • Remove(object value) (method)
  • RemoveAt(int index) (method)
  • RemoveRange(int index, int count) (method)
  • Reverse() (method)
  • Reverse(int index, int count) (method)
  • Sort() (method)
  • Sort(IComparer comparer) (method)
  • ToArray() (method)
  • TrimToSize() (method)

Example


using System.Collections;

// Create an ArrayList
ArrayList myList = new ArrayList();

// Add elements
myList.Add("Apple");
myList.Add(123);
myList.Add(true);

// Access elements
Console.WriteLine(myList[0]); // Output: Apple
Console.WriteLine(myList.Count); // Output: 3

// Iterate through the list
foreach (object item in myList)
{
    Console.WriteLine(item);
}
                        

CaseInsensitiveComparer

Compares two objects for equality, ignoring case.

public sealed class CaseInsensitiveComparer : IComparer, ISerializable

Comparer

Provides an object that compares two types of objects.

public sealed class Comparer : IComparer, ISerializable

Structs

DictionaryEntry

Represents a key/value pair that can be set or retrieved.

public struct DictionaryEntry

Members

  • Key (property)
  • Value (property)
  • ToString() (method)

Enums

CollectionChangeType

Describes the type of change that occurred in a collection.

public enum CollectionChangeType

Members

  • Add
  • Remove
  • Refresh