.NET 8 brings another number of innovations. One of them is the ability to compile ASP.NET Core application in AOT (ahead-of-time) mode. In this regime, however, forget about MVC, Blazor or SignalR. On the other hand, you will be rewarded with an application that will be smaller, take up less memory and start significantly faster. In addition, .NET 8 also brings the ability to easily generate random strings. And C# was not left out either, which in its 12th version fundamentally simplifies class notation.
What’s new in the Base Class Library?
Frozen collections
.NET includes new type collections
FrozenDictionary<TKey,TValue>
andFrozenSet<T>
.
You may wonder why this is the case, when .NET already contains
ImmutableDictionary<TKey,TValue>
andImmutableHashSet<T>
?
The answer lies in the way they are used. Frozen collections are optimized for read speed. It is suitable, for example, for configuring an application that is created only at its startup and values are often read from it. However, creating such a collection is more time-consuming than in the case of immutable collections.
RandomNumberGenerator.GetString
Generating random tokens is straightforward in .NET 8:
var token = RandomNumberGenerator.GetString("abcdefghijklmnoqrstuvwxyz0123456789", 32);
The nice thing about this is that you can directly define what characters should appear in the token.
What’s new in Windows Forms?
Designing a form on a high-resolution PC will no longer be as difficult, because you can set Visual Studio to always use 96 DPI to render the form design tab.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
+ <ForceDesignerDPIUnaware>true</ForceDesignerDPIUnaware>
</PropertyGroup>
</Project>
Also, be sure to read the traditional summary of performance improvements.
What’s new in C# 12?
Primary constructors
Often, the parameters of a class constructor were just copied into its body to be later available to its methods. Now, constructor parameters are available to all methods throughout the lifetime of the class.
class Car(string brand, Color color) {
public string Brand => brand;
public Color color => color;
}
Collection expressions
Whenever we need to create a collection, we can use the abbreviated []
similar to JavaScript. This new syntax also combines well with the ability to create new instances of a class without specifying its type in places where the type is known in advance.
List<Car> cars = [
new("Jaguar", Color.DarkGreen),
new("Land Rover", Color.SandyBrown),
new("Toyota", Color.Silver)
];
.NET Aspire
If microservices-based application architecture isn't your cup of tea, you can stick with a classic monolithic application. However, there is still room for improvement in development, deployment, configuration and telemetry. The more complex the application, the harder it is to run in a test environment. One possible solution may be .NET Apire. It’s something that understands how your app is put together from each project. It can run it locally as a whole, and as a whole, it can also monitor and deploy to the cloud. However, an even greater benefit is that it brings some standardization to considerable chaos.