Tried to run Run Code Analysis on a project here, and got a number of warnings that said something like this:
CA1002 : Microsoft.Design : Change 'List<SomeType>' in 'SomeClass.SomeProtectedOrPublicProperty' to use Collection, ReadOnlyCollection or KeyedCollection
Why should I use Collection<T>
instead of List<T>
? When I look at the msdn documentation, they seem almost equal. After reading the error help for the warning, I found that
System.Collections.Generic.List(T)_is a generic collection designed for performance not inheritance and, therefore, does not contain any virtual members.
But what does this really mean? And what should I be doing instead?
Should I keep using List<T>
internally, and then in the properties return a new Collection<T>(someList)
instead? Or should I just start using Collection<T>
instead of List<T>
?