System.Collections.Generic.ICollection<T> Interface

public interface ICollection<T>: IEnumerable<T>

Base Types

This type implements IEnumerable<T>.

Assembly

mscorlib

Library

BCL

Summary

Defines size and copying methods for all generic collections.

Description

[Note: This interface is the base interface for classes in the System.Collections.Generic namespace.

This interface extends IEnumerable<T>; System.Collections.Generic.IDictionary<T,U> and IList<T> are more specialized interfaces that extend ICollection<T>.

Some collections that limit access to their elements, like the System.Collections.Generic.Queue<T>class and the System.Collections.Generic.Stack<T> class, directly implement the ICollection<T> interface.

]

See Also

System.Collections.Generic Namespace

Members

ICollection<T> Methods

ICollection<T>.Add Method
ICollection<T>.Clear Method
ICollection<T>.Contains Method
ICollection<T>.CopyTo Method
ICollection<T>.Remove Method

ICollection<T> Properties

ICollection<T>.Count Property
ICollection<T>.IsReadOnly Property


ICollection<T>.Add Method

void Add(T item)

Summary

Adds an item to the current collection.

Parameters

item
The item to add to the current collection.

Exceptions

Exception TypeCondition
System.NotSupportedExceptionThe current collection is read-only.

See Also

System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic Namespace

ICollection<T>.Clear Method

void Clear()

Summary

Removes all items from the current collection.

Exceptions

Exception TypeCondition
System.NotSupportedExceptionThe current collection is read-only.

Description

System.Collections.Generic.ICollection<T>.Count is set to zero.

See Also

System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic Namespace

ICollection<T>.Contains Method

bool Contains(T item)

Summary

Determines whether the current collection contains a specific value.

Parameters

item
The object to locate in the current collection.

Return Value

true , if item is found in the current collection; otherwise, false .

Description

Implementations of this interface can vary in how they determine equality of objects; for example, some types use the default comparer, while others allow the user to specify the comparer to be used.

See Also

System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic Namespace

ICollection<T>.CopyTo Method

void CopyTo(T[] array, int index)

Summary

Copies the elements of the current collection to a Array, starting at the specified index.

Parameters

array
A one-dimensional, zero-based Array that is the destination of the elements copied from the current instance.
index
A Int32 that specifies the zero-based index in array at which copying begins.

Exceptions

Exception TypeCondition
ArgumentNullExceptionarray is null .
ArgumentOutOfRangeExceptionindex < 0.
ArgumentExceptionarray has more than one dimension.

-or-

index is greater than or equal to array.Length.

-or-

The sum of index and the System.Collections.ICollection.Count of the current instance is greater than array.Length.

-or-

Type T is not assignable to the element type of the destination array.

Description

This operation overwrites the current contents of the array.

See Also

System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic Namespace

ICollection<T>.Remove Method

bool Remove(T item)

Summary

Removes the first occurrence of an item from the current collection.

Parameters

item
The item to remove from the current collection.

Return Value

true , if item was removed from the current collection; false if item was not found in the current collection.

Exceptions

Exception TypeCondition
System.NotSupportedExceptionThe current collection is read-only.

Description

If item was found, but cannot be removed for some reason, some unspecified exception is thrown.

Implementations of this interface can vary in how they determine equality of objects; for example, some types use the default comparer, while others allow the user to specify the comparer to be used.

See Also

System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic Namespace

ICollection<T>.Count Property

int Count { get; }

Summary

Gets the number of elements contained in the current instance.

Property Value

A Int32 that indicates the number of elements contained in the current instance.

Description

This property is read-only.

See Also

System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic Namespace

ICollection<T>.IsReadOnly Property

bool IsReadOnly { get; }

Summary

Indicates whether the current collection is read-only.

Property Value

true , if the current collection is read-only; otherwise, false .

Description

This property is read-only.

A collection that is read-only does not allow the addition, removal, or modification of elements after the collection is created.

See Also

System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic Namespace