ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Inline 'out' variable declaration

Last modified: 04 June 2024

This inspection suggests inlining the out variable declaration to simplify your code and increase readability.

Starting with C# 7.0, as a part of enhancements to out variables, you can declare out variables in the argument list of a method, rather than writing a separate declaration statement.

As you can see, after the quick-fix the scope of value is narrowed down to the if statement, which follows the principle of limiting variable scope as much as possible. Furthermore, it helps you locate variable declarations more easily because they are typically closer to where the variables are first used in the code. Its availability in the preceding code lines is also removed, preventing potential misuse of the uninitialized variable.