public interface ICollection : IEnumerable
This type implements IEnumerable.
mscorlib
BCL
Serves as the base interface for implementing collection classes. Defines size, enumeration, and synchronization methods for all system collections.
[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.]
System.Collections Namespace
ICollection Methods
ICollection Properties
ICollection.Count Property
ICollection.IsSynchronized Property
ICollection.SyncRoot Property
void CopyTo(Array array, int index);
Copies the elements from the current instance to the specified Array, starting at the specified index in the array.
- 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.
Exception Type Condition ArgumentNullException array is null
.ArgumentOutOfRangeException index < 0. ArgumentException array has more than one dimension. index is greater than or equal to array.Length.
The sum of index and the System.Collections.ICollection.Count of the current instance is greater than array.Length.
InvalidCastException At least one element in the current instance is not assignment-compatible with the type of array.
[Behaviors: As described above.]
[Usage: Use this method to copy from a collection to a Array.]
System.Collections.ICollection Interface, System.Collections Namespace
int Count { get; }
Gets the number of elements contained in the current instance.
A Int32 that indicates the number of elements contained in the current instance.
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.
]
System.Collections.ICollection Interface, System.Collections Namespace
bool IsSynchronized { get; }
Gets a Boolean indicating whether access to the current instance is synchronized (thread-safe).
true
if access to the current instance is synchronized (thread-safe); otherwise,false
.
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. ]
System.Collections.ICollection Interface, System.Collections Namespace
object SyncRoot { get; }
Gets a Object that can be used for thread-safe synchronized access to the current instance.
A Object that can be used for thread-safe synchronized access to the current instance.
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.
]
System.Collections.ICollection Interface, System.Collections Namespace