[Mono-list] Problem with the 'is' operator, a bug in the mono runtime??

Daniel Stodden stodden@in.tum.de
27 Jun 2002 21:01:33 +0200


On Thu, 2002-06-27 at 12:07, Jaime Anguiano Olarra wrote:
> Yes!. Sorry, I might be too blind. :-/
> 
> Thanks,
> 
> Jaime.
> 
> El jue, 27-06-2002 a las 12:08, Dwivedi , Ajay Kumar escribió:
> > > if (modem is ISpherical)
> > > {
> > > 	ISpherical isModem = (ISpherical) modem;
> > > 	modem.Roll();
> > > }

btw:

you're generating _two_ identical typechecks with these statements.
one explicit via 'is' and an implicit second check during the actual
cast, after the original one already succeeded.
good compilers might optimize this away in future. afaik, csc currently
doesn't.

a more efficient version in C# is written by using the 'as' keyword,
which gets you a null if the type is incompatible.

ISpherical isModem = modem as ISperical;
if ( isModem )
	..
else
	..

see?


regards,
dns

-- 
___________________________________________________________________________
 mailto:stodden@in.tum.de