Is type casting slow (C#)

Started by
3 comments, last by Telastyn 15 years, 5 months ago
Is type casting like this (DerivedClass)BaseClassObject slow?
J.W.
Advertisement
No.
It's slower than BaseClassObject as DerivedClass, though, from what I recall, but not significantly.
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]
Mike Popoloski | Journal | SlimDX
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.

This topic is closed to new replies.

Advertisement