Performance: Expanded & Expression Bodied Methods

Updated January 2024

A contemporary approach to crafting concise methods in .NET involves using expression-bodied methods. The conventional or expanded method appears as follows:

public Person CreatePerson()
{
    return base.CreatePerson<Person>();
}

Converting this method to an expression-bodied method results in the following:

public Person CreatePerson() => base.CreatePerson<Person>();

I was curious to determine if utilizing expression-bodied methods would result in better performance.

Benchmark Results

The results below indicate that the performance difference is negligible and challenging to discern.

I recommend using either of the ways to create a method depending on the coding standards for your team.

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.


Discover more from dotNetTips.com

Subscribe to get the latest posts sent to your email.

Leave a comment

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