Quote:
I have to say I am not extremely well familiar with C# internals but I
doubt it calls a method for a simple cast. Casting an instance from
object to string will probably only tell the compiler not to report the
typical incompatible types message - along with additional checks for
possible unsupported casting exceptions.
|
Hmmm... I'm not sure about the C# compiler, and even less sure about
the JIT compiler (remember the C# 'compiler' actually translates source
code into MSIL !), but if you had to design the compiler, wouldn't you
simply make it instantiate an 'anonymous' instance of the class that
the object needs to be converted to and use that instance from that
point on (till end of scope, evidently) ?
I got a feeling it might be more complicated to tell the compiler not
to report errors than to make an instance of the casted-to class and
use that (this second alternative sounds safer to me too, on top of
that).
F.O.R.