pdavila (10) [Avatar] Offline

On page 129 (chapter 5) in your book, you have a table where you describe various interfaces. Your description of the IList interface says that IList is an ICollection. Also, your description for the ICollection says that it is an IEnumerable. The .NET documentation overview on the CollectionBase class has the following declaration.

public abstract class CollectionBase : IList, ICollection, IEnumerable

My confusion is the following. If IList is an ICollection, and if ICollection is an IEnumerable, shouldn't the declaration just be the following?

public abstract class CollectionBase : IList

I apologize for all these detailed questions. I think I got out of bed this morning with the urge to type.

Thanks for the help,

eebrown (89) [Avatar] Offline
Re: CollectionBase : IList, ICollection, IEnumerable
Hey Peter,

Sorry for the delay, just wanted to make sure my first thought was indeed correct. You are correct that the extra interfaces listed are not required.

If you look at the C# specifications, an interface inherits all members from any base interfaces, so the IList interface implicitly defines the members of ICollection and IEnumerable.

On the other hand, listing the members does not hurt anything either. If you look around the .NET Framework classes, they consistently list the base interface members in such situations. And if you think about it, listing these explicitly does make it clearly that the CollectionBase class defines all three interfaces.

Let me know if you have further questions,