Code Inspection: Redundant type specification in default expression
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.
With 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:
After the quick-fix