If your method returns a reference type or a null, it can be implemented in the following ways:
Example 1
var result = person != null ? person : null;
return result;
Example 2
var result =person ?? null;
return result;
Benchmark Results
To assess performance, the null coalesce approach (Example 2) is found to be 1.12 times more efficient compared to the ternary conditional expression (Example 1).


This is how I have it setup in my EditorConfig:
dotnet_diagnostic.IDE0029.severity = suggestion
Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks
Make a one-time donation
Make a monthly donation
Make a yearly donation
Choose an amount
Or enter a custom amount
Your contribution is appreciated.
Your contribution is appreciated.
Your contribution is appreciated.
DonateDonate monthlyDonate yearlyIf 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.

