I was advised to change a List<string>
property to a Collection<string>
, in a base class, because it is more appropriate for inheritance.
This 'rule' was referred to: https://msdn.microsoft.com/en-us/library/ms182142.aspx
System.Collections.Generic.List is a generic collection that is designed for performance and not inheritance. System.Collections.Generic.List does not contain virtual members that make it easier to change the behavior of an inherited class. The following generic collections are designed for inheritance and should be exposed instead of System.Collections.Generic.List.
System.Collections.ObjectModel.Collection<T> System.Collections.ObjectModel.ReadOnlyCollection<T> System.Collections.ObjectModel.KeyedCollection<TKey, TItem>
Does a similar rule apply to Dictionary<string, string>
?
I ask because it is also in the System.Collections.Generic
namespace. Or maybe I have misunderstood and the rule only applies to Lists
.
BTW, the Dictionary
purpose is to hold errors (in a similar format to ModelState). I am not currently sure at exactly what stage I will be adding errors to it.
If I should be avoiding Dictionary<string, string>
in the base class, what should I be using in it's place?
I have come across KeyedCollection
but not sure if that is a good replacement.