Re: Performance cost of casting

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 07/19/04


Date: Mon, 19 Jul 2004 17:59:04 +0100

Joel Wilson <joelycat@hotmail.com> wrote:
> It's more of an academic question of casting vs. Convert.To(). I assume
> the "small" performance hit is a typecheck on the object being cast.

Yes. Using the "as" operator (for reference types) is marginally faster
in the current CLR, and certainly using "as" and then a nullity check
is faster than "is" and then a cast, but most of the time it shouldn't
have any significant impact.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too