ICollection
ICollection is a non-generic interface in the .NET ecosystem, defined in the System.Collections namespace. It represents a collection of objects that can be counted, enumerated, and copied to an array. It is implemented by many classic non-generic collections such as ArrayList, Hashtable, Queue, and Stack. The interface is part of the broader collection framework that precedes generics and provides a common contract for various collection types.
Key members and characteristics include:
- Count: a property that returns the number of elements in the collection.
- CopyTo: a method that copies the elements of the collection into a one-dimensional array, starting at
- IsSynchronized: a property indicating whether access to the collection is synchronized (thread-safe).
- SyncRoot: a property that returns an object used to synchronize access to the collection.
Enumeration is provided through the IEnumerable interface, which ICollection extends. This means that a collection implementing
Relationship to generic variants: In modern .NET development, a generic counterpart, ICollection<T> in System.Collections.Generic, provides a
Usage notes: Developers typically use ICollection when implementing or consuming non-generic collections or when maintaining compatibility