Jump to content
Xtreme .Net Talk

Difference between List and Innerlist in a collectionbase


Recommended Posts

  • Leaders
Posted

I don't think the answer is as easy as just pointing him/her to msdn. I just had a look at the reference and must confess that it's still not entirely clear.

 

It looks like the InnerList just provides you with a specific implementation of the IList and they've also provided the flexibility with the List for CollectionBase implementors to implement an IList interface as they see fit (ie. if an ArrayList wasn't the most efficient structure for your needs). Though it seems that one could implement the List property by simply pointing to the InnerList property.

 

Having said that, it's just a guess, I've not implemented a CollectionBase so I have no firsthand knowledge.

--tim
  • 2 years later...
Posted

I'm a little late to this scene but I feel it's important to close this thread.

 

I came across this thread because I was interested to know the memory and performance implications of choosing one property over the other. The following excerpt from http://msdn.microsoft.com/msdnmag/issues/04/09/AdvancedBasics/ makes it clear.

 

 

The CollectionBase class provides two properties that allow you to interact with its internal ArrayList: the InnerList property returns an ArrayList reference and the List property returns an IList.

 

The difference between the two is that the List property acts as a wrapper around the InnerList property. When you call the List.Add method, for example, the CollectionBase class first calls its OnValidate and OnInsert overrides, and then calls the InnerList.Add method. After the call to InnerList.Add, the class calls the OnInsertComplete method override. These methods allow you to provide code that runs both before and after the data is inserted into the data structure, and let you validate the data as well. For Adam's example, working with the InnerList property directly is simplest because there's no need to override the other procedures.

 

So InnerList should be minimally better than List. I suppose a remaining option is to inherit the Array type and build the basic functionality [including dynamic resizing, i.e. vector] that I need. Fun.

 

Eldar

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...