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: Add explicit 'return' or 'continue' before local functions

Last modified: 08 April 2024

When you have one or more local functions defined at the end of a method, ReSharper suggests adding an explicit return between the last executable statement and the local function definition. The method will return at that point anyway, but making this explicit will enhance the clarity of the method's control flow for readers. This is particularly beneficial if the local function definition is lengthy, or if there are multiple local functions. In these instances, the reader will not have to scroll to the end of the method to check for more executable statements after the local function definitions.

Here is an example:

The same applies when a local function is defined inside a block. In such cases, adding an explicit continue statement makes the structure of the block more comprehensible: