ICollection Interface (System.Collections)

Provides a collection that can be iterated over.

Summary

The ICollection interface represents a collection that can be iterated over. It provides a way to access and manipulate elements in the collection using methods like Add, Remove, and Count.

It's a fundamental interface in the .NET Framework's System.Collections namespace and is often used in conjunction with other collection types like ArrayList and List.

Methods

Method Name Description
Add(object item) Adds an item to the collection.
Remove(object item) Removes an item from the collection.
Contains(object item) Determines if the collection contains a specified item.
Count Gets the number of items in the collection.
Clear() Removes all items from the collection.

Example


// Example using ICollection (Conceptual - specific implementation details will vary)
ICollection names = new ArrayList();
names.Add("Alice");
names.Add("Bob");
names.Add("Charlie");

foreach (string name in names)
{
    Console.WriteLine(name);
}

See Also