Collections should implement generic interface
Collections should implement generic interface
Microsoft docsDescription
To broaden the usability of a collection, implement one of the generic collection interfaces. Then the collection can be used to populate generic collection types such as the following:
- System.Collections.Generic.List`1
- System.Collections.Generic.Queue`1
- System.Collections.Generic.Stack`1
Cause
A type implements the System.Collections.IEnumerable interface but does not implement the System.Collections.Generic.IEnumerable`1 interface, and the containing assembly targets .NET. This rule ignores types that implement System.Collections.IDictionary.
By default, this rule only looks at externally visible types, but this is configurable. You can also configure additional interfaces to require that a generic interface be implemented.
How to fix violations
To fix a violation of this rule, implement one of the following generic collection interfaces:
- System.Collections.Generic.IEnumerable`1
- System.Collections.Generic.ICollection`1
- System.Collections.Generic.IList`1
Example
#pragma warning disable CA1010
// The code that's violating the rule is on this line.
#pragma warning restore CA1010When to suppress
It is safe to suppress a warning from this rule; however, the use of the collection will be more limited.