General Performance Tip: Type Conversion

In programming, there is often a need to convert one type to another. This process has been commonly executed in .NET using the traditional syntax, as illustrated below:

var person = (IPerson<Address>)personManager;

A newer method for type conversion involves the use of the “as” keyword, offering a more readable alternative:

var person = personManager as IPerson<Address>;

Benchmark Results

 As evident from these results, utilizing “as” is slightly more performant.

Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$100.00
$5.00
$15.00
$100.00
$5.00
$15.00
$100.00

Or enter a custom amount

$

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

If you liked this article, please buy David a cup of Coffee by going here: https://www.buymeacoffee.com/dotnetdave

© The information in this article is copywritten and cannot be preproduced in any way without express permission from David McCarter.

One thought on “General Performance Tip: Type Conversion

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.