What is the difference between Collection<T> and List<T> ?

  • Thread starter Thread starter Oleg Subachev
  • Start date Start date
O

Oleg Subachev

What is the difference between Collection<T> and List<T> ?

Both of them implement the same set of interfaces.


Oleg Subachev
 
Oleg,

The Collection<T> class is intended to be used when you need to
customize the actions of altering the list. For example, the protected
InsertItem method would be overriden when you have custom logic that you
need to implement when an item is inserted into the collection.

The List<T> class does not have these overrides.
 
The only place to use Collection is a class you create that inherits
from it. Use List for everything else. List has a richer interface
than Collection.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top