A
Andreas Mueller
Hi All,
I recently came across a code snippet similar to the one below generated
by a code generator. I asked myself, if the compiler will optimize this
or if the program will do the actual (needless) cast at runtime:
class SomeGeneratedClass
{
public object Foo()
{
return null;//returns something sensible in real live
}
}
class OtherGeneratedClass
{
public void void Xox()
{
object o = (object)m_.Foo();//needless cast!
//will the compiler optimize this?
}
private SomeGeneratedClassm_ = new SomeGeneratedClass();
}
If it does optimize it, will it also optimize this situation?
class Xox : ICloneable
{
// hidden interface implementation
object ICloneable.Clone(){ return null; }
}
class Other
{
public void Foo()
{
Xox x = new Xox();
object o = ((ICloneable)x).Clone();//How about this?
// will it do a cast to ICloneable at runtime?
}
}
Thank you very much in advance,
Andy
I recently came across a code snippet similar to the one below generated
by a code generator. I asked myself, if the compiler will optimize this
or if the program will do the actual (needless) cast at runtime:
class SomeGeneratedClass
{
public object Foo()
{
return null;//returns something sensible in real live
}
}
class OtherGeneratedClass
{
public void void Xox()
{
object o = (object)m_.Foo();//needless cast!
//will the compiler optimize this?
}
private SomeGeneratedClassm_ = new SomeGeneratedClass();
}
If it does optimize it, will it also optimize this situation?
class Xox : ICloneable
{
// hidden interface implementation
object ICloneable.Clone(){ return null; }
}
class Other
{
public void Foo()
{
Xox x = new Xox();
object o = ((ICloneable)x).Clone();//How about this?
// will it do a cast to ICloneable at runtime?
}
}
Thank you very much in advance,
Andy