What’s new in .NET 6 and C# 10?
.NET 6 and C# 10 have brought many new features. We cannot visit them all but we explore a selection of those features that are leveraged in the book or that I thought were worth mentioning.
In this section, we explore the following C# 10 features:
- File-scoped namespaces
- Global
using
directives - Implicit
using
directives - Constant interpolated strings
- Record struct
- Minimal hosting model
- Minimal APIs
- Nullable reference types (added in C# 8 and enabled by default in .NET 6 templates)
File-scoped namespaces
Declaring a file-scoped namespace reduces the horizontal indentation of our code files by removing the need to declare a block ({}
).
We previously wrote:
namespace Vehicles
{
public interface IVehicleFactory
{
// Omitted members
}
}
We now can write:
namespace Vehicles;
public interface IVehicleFactory
{
// Omitted members
}
Saving...