Code inspection: Use preferred style of default value expression when type is 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, JetBrains Rider highlights type specifications as redundant and helps remove them:
![JetBrains Rider syntax style inspection: Use 'default' literal JetBrains Rider syntax style inspection: Use 'default' literal](https://resources.jetbrains.com.cn/help/img/rider/2024.2/default_value_type_remove.png)
If you prefer to have explicit type specifications in your code, you can change the corresponding preferences and JetBrains Rider will help you add missing type specifications:
![JetBrains Rider syntax style inspection: Specify type JetBrains Rider syntax style inspection: Specify type](https://resources.jetbrains.com.cn/help/img/rider/2024.2/default_value_type_add.png)
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)').