Inheriting from List

If you want to create a publicly exposed animal collection you should not inherit from List<T> and instead inherit from Collection<T> and use the postfix Collection in the class name. Example: AnimalCollection : Collection<Animal>.

This is supported by the framework design guidelines, more specifically:

DO NOT use ArrayList, List<T>,
Hashtable, or Dictionary<K,V> in
public APIs. Use Collection<T>,
ReadOnlyCollection<T>,
KeyedCollection<K,T>, or
CollectionBase subtypes instead. Note
that the generic collections are only
supported in the Framework version 2.0
and above.

Leave a Comment