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
- Target-typed new C# 9.0 achieves the same effect with the
new
keyword