As part of the push to eliminate unnecessary duplication of type specification the default keyword used to initialize reference types to null, numeric types to 0 and booleans to false can now have the type omitted provided the compiler can definitively determine which type it must be.
Code
csharp
static T LoadValues<T>(int index)
{
if (index < 0) return default;
// ...
}csharp
static T LoadValues<T>(int index)
{
if (index < 0) return default(T);
// ...
}Notes
- Target-typed new C# 9.0 brings the same type inference to
new, creating an instance rather than a default value