0

Would anyone explain to me why in the abstract CollectionBase class (in System.Collections which derives from IList) it does not have the IList members implemented? I thought it was obligatory.

System.Collection.CollectionBase

adrianbanks
  • 81,306
  • 22
  • 176
  • 206
Mikatsu
  • 530
  • 2
  • 4
  • 15
  • 1
    [**It**](http://msdn.microsoft.com/en-us/library/system.collections.collectionbase.aspx) implements e.g. `IList.Add, IList.Contains, IList.IndexOf, IList.Insert, IList.IsFixedSize, IList.IsReadOnly, IList.Item, IList.Remove`. So what's the question? – Tim Schmelter Feb 24 '13 at 21:56
  • Thats exactly what i am searching for but when i check CollectionBase definition i cant see no IList implementation... – Mikatsu Feb 24 '13 at 22:15
  • Where are you looking for the _definition_ of `CollectionBase`? I always look first at MSDN: http://msdn.microsoft.com/en-us/library/system.collections.collectionbase.aspx – Tim Schmelter Feb 24 '13 at 22:16
  • I do check definitions with F12 or Context Menu > Visual Studio 2010 .NET 4.0. U re right on msdn i can see the explicit implementation which i was missing i am confused now why i can't see them in Collection name space here? – Mikatsu Feb 24 '13 at 22:25

1 Answers1

2

It implements IList explicitly, so you'll need to cast your CollectionBase instance to IList to access those members.

IList list = (IList)collectionBase;
list.Add(...);
svick
  • 236,525
  • 50
  • 385
  • 514
Lee
  • 142,018
  • 20
  • 234
  • 287
  • When i check definition for CollectionBase i see non of them they should be explicitly defined in CollectionBase or not? – Mikatsu Feb 24 '13 at 22:10
  • @Mikatsu - I'm not sure where you're getting the definition from, but if you look [here](http://msdn.microsoft.com/en-us/library/system.collections.collectionbase.aspx) and scroll down to 'Explicit Interface Implementations', you'll see it explicitly implements `IList` and `ICollection`. – Lee Feb 24 '13 at 22:18
  • i ve added an image on start post why is it different to msdn? i use F12 in Visual Studio. – Mikatsu Feb 24 '13 at 22:30
  • @Mikatsu - Explicitly implemented interface methods are private to the implementing class, and Visual Studio appears to only show public and protected methods in the definition. – Lee Feb 24 '13 at 22:36