Avoid excessive parameters on generic types







Breaking Change



An externally visible generic type has more than two type parameters.

Rule Description

The more type parameters a generic type contains, the more difficult it is to know and remember what each type parameter represents. It is usually obvious with one type parameter, as in List<T>, and in certain cases with two type parameters, as in Dictionary<TKey, TValue>. If there are more than two type parameters, the difficulty becomes too great for most users, for example, TooManyTypeParameters<T, K, V> in C# or TooManyTypeParameters(Of T, K, V) in Visual Basic.

How to Fix Violations

To fix a violation of this rule, change the design to use no more than two type parameters.

When to Suppress Warnings

Do not suppress a warning from this rule unless the design absolutely requires more than two type parameters. Providing generics in a syntax that is easy to understand and use reduces the time that is required to learn and increases the adoption rate of new libraries.


The following example shows a class that defines 3 generic type parameters which violate the rule.

Imports System     

Namespace Samples

    ' Violates this rule  
    Public Class Tuple(Of T1, T2, T3)
    End Class 

End Namespace
using System;

namespace Samples
    // Violates this rule    
    public class Tuple<T1, T2, T3>   
using namespace System;

namespace Samples
    // Violaties this rule 
    generic <typename T1, typename T2, typename T3>
    public ref class Tuple

Collections should implement generic interface

Do not declare static members on generic types

Do not expose generic lists

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


Generics (C# Programming Guide)