Can 'is' followed by cast by optimized away



Hi,

Can the following ugly type-switching code by optimized
by the compiler/jitter?:

object o = ...;
if( o is Foo )
return (Foo)o;

Arguably, the cast is guranteed to succeed, but do the
compiler take advantage of that?

If yes, would it be possible to each that conclusion
by looking at the assembler output?

Thanks

-Thorsten


.



Relevant Pages

  • Re: Can is followed by cast by optimized away
    ... > Can the following ugly type-switching code by optimized ... > by the compiler/jitter?: ... return o as Foo; ... (works only on reference types, not on value types, as they can't be null) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can is followed by cast by optimized away
    ... >> Can the following ugly type-switching code by optimized ... > return o as Foo; ... (one cast to see if it is the right type, ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)