ReSharper 2024.1 Help

Code Inspection: Use preferred style of default value expression when type is evident

Category

Syntax Style

ID

ArrangeDefaultValueWhenTypeEvident

EditorConfig

resharper_arrange_default_value_when_type_evident_highlighting

Default severity

Suggestion

Language

C#

Requires SWA

No

When you evaluate a default value of a type with the default value expression, and the type can be inferred, you can use either the default(T) operator or the default expression.

In other words, type specification (T) is optional with default when the type can be inferred.

Depending on the context, the optional type specification can either clutter your code with redundant information or, on the contrary, improve the readability.

By default, ReSharper highlights type specifications as redundant and helps remove them:

ReSharper syntax style inspection: Use 'default' literal

If you prefer to have explicit type specifications in your code, you can change the corresponding preferences and ReSharper will help you add missing type specifications:

ReSharper syntax style inspection: Specify type

For more information about configuring and enforcing your preferences for default value expressions, refer to Code Syntax Style: Default Value Expressions ('default' vs 'default(T)').

Last modified: 15 April 2024