Answer the question
In order to leave comments, you need to log in
Why would ICollection re-inherit the IEnumerable interface in C#?
Hello!
C# has an ICollection(T) which is declared like this:
public interface ICollection<T> : IEnumerable<T>, IEnumerable
{
int Count { get; }
bool IsReadOnly { get; }
void Add(T item);
void Clear();
bool Contains(T item);
void CopyTo(T[] array, int arrayIndex);
bool Remove(T item);
}
public interface IEnumerable<out T> : IEnumerable
{
IEnumerator<T> GetEnumerator();
}
Answer the question
In order to leave comments, you need to log in
This is for backwards compatibility. Nothing wrong with that.
And yes - the behavior will not change if you remove the direct inheritance of IEnumerable
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question