Performance of TypeCasting

It may be measurable if it’s being done billions of times with very little other work. I don’t know whether the CLR will effectively cache the fact that the cast worked, so it doesn’t need to do it again – if it doesn’t do so now, it might do so in a later release. It might do so in the 64 bit JIT but not the 32 bit version, or vice versa – you get the idea. I doubt that it would make a significant difference in normal code though.

Personally I like the readability of the second form more though, and that’s more important by far.

Leave a Comment