public interface ICollection<T>: IEnumerable<T>
This type implements IEnumerable<T>.
mscorlib
BCL
Defines size and copying methods for all generic collections.
[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.
]
System.Collections.Generic Namespace
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
void Add(T item)
Adds an item to the current collection.
- item
- The item to add to the current collection.
Exception Type Condition System.NotSupportedException The current collection is read-only.
System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic Namespace
void Clear()
Removes all items from the current collection.
Exception Type Condition System.NotSupportedException The current collection is read-only.
System.Collections.Generic.ICollection<T>.Count is set to zero.
System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic Namespace
bool Contains(T item)
Determines whether the current collection contains a specific value.
- item
- The object to locate in the current collection.
true
, if item is found in the current collection; otherwise,false
.
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.
System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic Namespace
void CopyTo(T[] array, int index)
Copies the elements of the current collection to a Array, starting at the specified index.
- 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. -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.
This operation overwrites the current contents of the array.
System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic Namespace
bool Remove(T item)
Removes the first occurrence of an item from the current collection.
- item
- The item to remove from the current collection.
true
, if item was removed from the current collection;false
if item was not found in the current collection.
Exception Type Condition System.NotSupportedException The current collection is read-only.
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.
System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic 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.
System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic Namespace
bool IsReadOnly { get; }
Indicates whether the current collection is read-only.
true
, if the current collection is read-only; otherwise,false
.
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.
System.Collections.Generic.ICollection<T> Interface, System.Collections.Generic Namespace