System.Collections.ICollection Interface

public interface ICollection : IEnumerable

Base Types

This type implements IEnumerable.

Assembly

mscorlib

Library

BCL

Summary

Serves as the base interface for implementing collection classes. Defines size, enumeration, and synchronization methods for all system collections.

Description

[Note: ICollection contains the System.Collections.ICollection.CopyTo(System.Array,System.Int32) method. The consumer of a collection object that implements this interface should call this method when copying the elements of that object to a Array.]

See Also

System.Collections Namespace

Members

ICollection Methods

ICollection.CopyTo Method

ICollection Properties

ICollection.Count Property
ICollection.IsSynchronized Property
ICollection.SyncRoot Property


ICollection.CopyTo Method

void CopyTo(Array array, int index);

Summary

Copies the elements from the current instance to the specified Array, starting at the specified index in the array.

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.

InvalidCastExceptionAt least one element in the current instance is not assignment-compatible with the type of array.

Description

[Behaviors: As described above.]

[Usage: Use this method to copy from a collection to a Array.]

See Also

System.Collections.ICollection Interface, System.Collections Namespace

ICollection.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.

[Behaviors: The System.Collections.ICollection.Count property is required to return the total number of elements contained in the current instance.

]

See Also

System.Collections.ICollection Interface, System.Collections Namespace

ICollection.IsSynchronized Property

bool IsSynchronized { get; }

Summary

Gets a Boolean indicating whether access to the current instance is synchronized (thread-safe).

Property Value

true if access to the current instance is synchronized (thread-safe); otherwise, false .

Description

This property is read-only.

[Behaviors: As described above.]

[Usage: To synchronize a collection, use System.Collections.ICollection.SyncRoot to obtain a Object with which to synchronize the collection. ]

See Also

System.Collections.ICollection Interface, System.Collections Namespace

ICollection.SyncRoot Property

object SyncRoot { get; }

Summary

Gets a Object that can be used for thread-safe synchronized access to the current instance.

Property Value

A Object that can be used for thread-safe synchronized access to the current instance.

Description

This property is read-only.

[Note: For collections with no publicly available underlying store, the expected implementation is to simply return the current instance. Note that this might not be sufficient for collections that wrap other collections; those should return the underlying collection's System.Collections.ICollection.SyncRoot property.

]

See Also

System.Collections.ICollection Interface, System.Collections Namespace