[Mono-list] VBNC in Mono.

Jonathan Gilbert 2a5gjx302 at sneakemail.com
Thu Sep 14 11:22:34 EDT 2006

At 10:52 AM 13/09/2006 +0200, Kornél Pál wrote:
>>But what is the reason for changing some of the .ToString into DirectCast ?
>If you check for the exact data type (as you did in all the cases I modified 
>to DirectCast) either for value types of for reference types there is no use 
>to do tricky conversions because we know the type of the variable so a 
>DirectCast is the most efficient and most reasonable conversion because 
>after a TypeOf <value> Is <type> a DirectCast(<value>, <type>) will succeed 
>for sure. So I only suggest to change CType to DirectCast in these contexts.

In the case of an Object that is known to contain a String, a call to
.ToString() may perform better than a direct cast. A cast still needs to
check the type, even though the code has already just done it with a TypeOf
(I'd be very surprised if the JIT can detect that pattern and only do one
check). Calling .ToString() will be a virtual call to "return this;". It'd
be interesting to do a comparison, but my intuition is that .ToString()
would be significantly faster in this case.

Jonathan Gilbert

More information about the Mono-list mailing list