• Advertisement
Sign in to follow this  

Is type casting slow (C#)

This topic is 3388 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is type casting like this (DerivedClass)BaseClassObject slow?

Share this post


Link to post
Share on other sites
Advertisement
It's only slower if the conversion fails, as castclass will throw an exception while isinst will simply return null.

[Edited by - Mike.Popoloski on November 9, 2008 10:53:46 PM]

Share this post


Link to post
Share on other sites
Not so much, but the need for it is indicative of a design failure somewhere. Sometimes it's small, or saves a ton of time, or a corner case... but something that tells you to take a second look at the design. Make sure you're stepping outside the norm for a good reason.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement