As in this example:
switch ( myObj.GetType ( ) )
{
case typeof(MyObject):
Console.WriteLine ( \"MyObject is here\" );
break;
}
There's a good blog post on MSDN by Peter Hallam which explains the problems of switching on non-constant values.
"The order of the case labels becomes significant in determining which block of code gets executed. Because the case label expressions are not constant the compiler cannot verify that the values of the case labels are distinct, so this is a possibility which must be catered to. This runs counter to most programmers’ intuition about the switch statement in a couple of ways. Most programmers would be surprised to learn that changing the order of their case blocks changed the meaning of their program. To turn it around, it would be surprising if the expression being switched on was equal to an expression in a case label, but control didn’t go to that label."