ICollection<T> Interface

Represents a collection of objects of the specified generic type. This is the base interface for all generic collection types.

Namespace: System.Collections.Generic
Assembly: mscorlib.dll (or relevant assembly)

Remarks

The ICollection<T> interface is the base interface for collections that contain objects of a specified type. It defines methods and properties for manipulating the collection, such as adding, removing, copying, and checking for the presence of elements. It inherits from IEnumerable<T>, which allows you to iterate over the collection using a foreach loop.

Implementations of ICollection<T> should follow standard contract conventions, such as ensuring that the Count property always returns the correct number of elements, and that methods like Add and Remove behave as expected.

Methods

Method Description
void Add(T item) Adds an item to the end of the ICollection<T>.
void Clear() Removes all items from the ICollection<T>.
bool Contains(T item) Determines whether the ICollection<T> contains a specific value.
void CopyTo(T[] array, int arrayIndex) Copies the entire ICollection<T> to a compatible one-dimensional Array, starting at the specified index of the target array.
bool Remove(T item) Removes the first occurrence of a specific object from the ICollection<T>.

Properties

Property Description
int Count { get; } Gets the number of elements contained in the ICollection<T>.
bool IsReadOnly { get; } Gets a value indicating whether the ICollection<T> is read-only.

See Also

Assembly Information

This interface is typically found in the following assemblies:

  • mscorlib.dll (for .NET Framework)
  • System.Runtime.dll (for .NET Core / .NET 5+)