ReSharper 2024.1 Help

Code Inspection: Introduce optional parameters (private accessibility)

Category

Language Usage Opportunities

ID

IntroduceOptionalParameters.Local

EditorConfig

resharper_introduce_optional_parameters_local_highlighting

Default severity

Suggestion

Language

C#

Requires SWA

No

If the single purpose of an overloaded function is to call the 'implementation' function with default values for some arguments, optional arguments (introduced in C# 4.0) can be used in the 'implementation' function instead of this overload.

ReSharper helps you detect such overloads and automatically remove them, making the corresponding parameters of the 'implementation' functions optional.

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

void Foo(object value) { Foo(value, true); } void Foo(object value, bool flag) { //implementation }
void Foo(object value, bool flag = true) { //implementation }
Last modified: 15 April 2024