Difference between DirectCast and CType
Posted on 2005-04-18
If I want to resume the differences, as explained in the MSDN:
- CType can be used for narrowing or widening conversion
- to use DirectCast, there must be an heritance or implementation relation between the classes
- DirectCast could be quicker because it doesn't use the Visual Basic run-time helper routines for conversion.
First question : what is the "Visual Basic run-time helper routines for conversion" ?
Second question : in the version 1.0 and 1.1 (the help has been modified in 2.0) it was specified that the dynamic type of the two objects must be identical to have DirectCast succeeds, whereas it is only specified a relation in inheritance or implementation in 2.0. But if you look to the generated MSIL code (I have looked in 2.0), you will notice that both classes are compiled using the directive "castclass"
So I wonder how one can be quicker that the second one if they are compiled in the identical code ?