CollectionBase versus ArrayList

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

All the examples I have seen about typed collections says to inherit from
CollectionBase and implement type-specific Add and Remove methods.
Considering that CollectionBase uses an ArayList for the actual list storage
(i.e. InnerList property), why would you do this instead of just inheriting
from ArrayList and overridding Add and Remove?

- Jason
 
Jason said:
All the examples I have seen about typed collections says to inherit from
CollectionBase and implement type-specific Add and Remove methods.
Considering that CollectionBase uses an ArayList for the actual list storage
(i.e. InnerList property), why would you do this instead of just inheriting
from ArrayList and overridding Add and Remove?

Because if you inherit from ArrayList, people can easily inadvertently
call the wrong overload. Inheriting from CollectionBase stops people
from using the wrong overload unless they specifically treat it as an
IList.
 
Back
Top