I am looking at a function with this template:
if( obj is SpecificClass1 )
{
((SpecificClass1)obj).SomeMethod1();
}
else if( obj is SpecificClass2 )
{
((SpecificClass2)obj).SomeMethod2();
}
else if( obj is SpecificClass3 )
{
((SpecificClass3)obj).SomeMethod3();
}
and get code performance analysis. Warning: CA1800 Do not overuse.
Why double casts (using the "is" operator in an if statement and as brackets enclosed in the body of each if) cannot be optimized by the compiler. I do not understand why this is a performance problem that the compiler cannot solve.
source
share