Do not expose generic lists

TypeName

DoNotExposeGenericLists

CheckId

CA1002

Category

Microsoft.Design

Breaking Change

Breaking

Cause

A type contains an externally visible member that is a System.Collections.Generic.List type, returns a System.Collections.Generic.List type, or whose signature includes a System.Collections.Generic.List parameter.

Rule Description

System.Collections.Generic.List is a generic collection designed for performance not inheritance and, therefore, does not contain any virtual members. The following generic collections are designed for inheritance and should be exposed instead of System.Collections.Generic.List.

How to Fix Violations

To fix a violation of this rule, change the System.Collections.Generic.List type to one of the generic collections designed for inheritance.

When to Exclude Warnings

Do not exclude a warning from this rule unless the assembly that raises this warning is not meant to be a reusable library. For example, it would be safe to exclude this warning in a performance tuned application where a performance benefit was gained from the use of generic lists.

Avoid excessive parameters on generic types

Collections should implement generic interface

Do not declare static members on generic types

Do not nest generic types in member signatures

Generic methods should provide type parameter

Use generic event handler instances

Use generics where appropriate

See Also

Concepts

Generics (C# Programming Guide)