Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I noticed for class like ArrayList implement IList, ICollection, and IEnumerable, instead of just IList which covers them all. Are there any benefits by doing this?
  • *Experts*
Posted

You have to implement all 3 interfaces if you inherit from IList, as IList is based on the others.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

I understand this, but MS did this:

 

class ArrayList : IList, ICollection, IEnumerable
{
   ...
}

 

instead of

class ArrayList : IList
{
   ...
}

 

You can see this from the object browser.

  • *Experts*
Posted

I did a quick test - I created a new ClassLibrary with one class that implements IList, compiled, and looked at it. It, too, shows ": IList, ICollection, IEnumerable" so that must be how .NET sees it. That kinda makes sense, as far as reflection goes - if you query a class that implements IList and IList implements ICollection, it stands to reason that querying the class through reflection will show both.

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...