Skip to content

Default literals C# 7.1code reduction

Omit the type when using `default` if the compiler can infer it.

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 providing the complier can definitively determine which type it must be.

Code

C#
static T LoadValues<T>(int index)
{
    if (index < 0) return default;
    // ...
}
C#
static T LoadValues<T>(int index)
{
    if (index < 0) return default(T);
    // ...
}

Notes

More information