TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C# Coding Standard
Search

7@610Checked automatically with code checker

Synopsis:Use generic constraints if applicable


Description:

Instead of casting to and from the object type in generic types or methods, use where constraints or the as operator to specify the exact characteristics of the generic parameter.

Wrong example:

class MyClass<T> 
{
    void SomeMethod(T t) 
    { 
        object temp = t; 
        SomeClass obj = (SomeClass) temp; 
    } 
}

Wrong example:

class MyClass<T> where T : SomeClass
{
    void SomeMethod(T t) 
    { 
        SomeClass obj = t; 
    } 
}



Literature References:
Aviva AV1240