Share via


ICollection Interface

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Defines size, enumerators, and synchronization methods for all nongeneric collections.

Namespace:  System.Collections
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Interface ICollection _
    Inherits IEnumerable
public interface ICollection : IEnumerable
public interface class ICollection : IEnumerable
type ICollection =  
    interface
        interface IEnumerable
    end
public interface ICollection extends IEnumerable

The ICollection type exposes the following members.

Properties

  Name Description
Public property Count Gets the number of elements contained in the ICollection.
Public property IsSynchronized Gets a value indicating whether access to the ICollection is synchronized (thread safe).
Public property SyncRoot Gets an object that can be used to synchronize access to the ICollection.

Top

Methods

  Name Description
Public method CopyTo Copies the elements of the ICollection to an Array, starting at a particular Array index.
Public method GetEnumerator Returns an enumerator that iterates through a collection. (Inherited from IEnumerable.)

Top

Remarks

The ICollection interface is the base interface for classes in the System.Collections namespace.

The ICollection interface extends IEnumerable; IDictionary and IList are more specialized interfaces that extend ICollection. An IDictionary implementation is a collection of key/value pairs, like the Hashtable class. An IList implementation is a collection of values and its members can be accessed by index, like the ArrayList class.

Some collections that limit access to their elements, such as the Queue class and the Stack class, directly implement the ICollection interface.

If neither the IDictionary interface nor the IList interface meet the requirements of the required collection, derive the new collection class from the ICollection interface instead for more flexibility.

See Also

Reference

System.Collections Namespace