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

Code Inspection: Redundant type specification in default expression

Last modified: 21 July 2022

In C#, we have been able to use default(T) when we did not know whether T would be a value type or reference type. Using default(T) would return null for reference types, or a zero-initialized value for value types. It’s pretty tedious to write though, as T could be a very long class name.

Starting from C# 7.1, we have a default literal that can be used instead and infers the type based on the context in which it’s used. It can be used in most places where we would normally use null, as it will work perfectly for both value and reference types.

ReSharper recognizes opportunities to use the default literal syntax where default(T) is being used. A quick-fix allows you to remove the redundant type specification: