Sobes.tech
Junior — Middle

What functions does the ICollection interface implement in standard libraries?

sobes.tech AI

Answer from AI

The ICollection interface in C# defines the basic methods and properties for working with collections. Key functions include:

  • Getting the number of elements via the Count property.
  • Adding and removing elements (depending on the implementation).
  • Checking for the presence of an element via the Contains method.
  • Copying elements to an array using CopyTo.
  • Supporting iteration over elements via IEnumerable.

Example usage:

ICollection<string> collection = new List<string>();
collection.Add("apple");
int count = collection.Count; // 1
bool hasApple = collection.Contains("apple");
What functions does the ICollection interface… - sobes.tech