ReSharper 2024.3 Help

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

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: 11 February 2024