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: Join local variable declaration and assignment

Last modified: 08 April 2024

If you declare a local variable and initialize it later without any conditions, ReSharper suggests joining the declaration and the assignment in the place where the variable is first initialized. This removes unnecessary line and improves readability of your code.

Here is an example of a quick-fix suggested by this inspection:

When ReSharper joins the declaration and the assignment of your variable, it will use var or an explicit type depending on your preferences.