ReSharper
 
Get ReSharper
You are viewing the documentation for an earlier version of ReSharper.

Code Syntax Style: Default Value Expressions ('default' vs 'default(T)')

Last modified: 21 July 2022

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.

Therefore, ReSharper provides two code style preferences for default value expressions:

  • when the type is evident from usage (for example, in parameter declarations or field initializations),

  • when the type is not evident (for example, in method call arguments or return statements).

ReSharper helps you enforce style preferences for default value expressions in the existing code and takes your preferences into account when it produces new code with code completion and code generation features, applies code templates and performs refactorings.