Deal of the Day

Home » Main » Manning Forums » 2006 » Windows Forms in Action and Windows Forms Programming with C#

Thread: CollectionBase : IList, ICollection, IEnumerable

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 1 - Pages: 1 - Last Post: Jan 22, 2005 6:23 PM by: eebrown
pdavila

Posts: 10
From: NJ - USA
Registered: 6/3/04
CollectionBase : IList, ICollection, IEnumerable
Posted: Jan 20, 2005 4:52 PM
  Click to reply to this thread Reply

Erik,

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,

Peter

eebrown

Posts: 89
From: Virginia
Registered: 12/18/03
Re: CollectionBase : IList, ICollection, IEnumerable
Posted: Jan 22, 2005 6:23 PM   in response to: pdavila in response to: pdavila
  Click to reply to this thread Reply

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,

Erik

Legend
Gold: 300 + pts
Silver: 100 - 299 pts
Bronze: 25 - 99 pts
Manning Author
Manning Staff