As part of .NET 8, there are a bunch of performance fixes and behind-the-scenes things that have been introduced. In this tutorial, we will focus on the code changes that you can expect to see within this release.
You can download .NET 8 from this location. In order to use .NET 8 within Visual Studio you will need to use preview features. You will need to install VS 2022, v17.6.01
System.Text.Json Updates
Within .NET 8, there have been some updates to JSON serialization. One of the coolest futures is the ability to convert your JSON into either snake case or kebab case. You can set the type you want to use with the JsonNamingPolicy
. This type allows you to pick from either CamelCase
, SnakeCaseLower
, SnakeCaseUpper
, KebabCaseLower
, or KebabCaseUpper
. The code below shows what snake-case looks like:
This is what kebab-case looks like:
Another cool feature is an improvement around being able to serialize properties that have been inherited via interfaces
. The following code shows an example where the properties from both the immediately implemented interface and its base interface are serialized. Lets us take this basic inheritance chain:
Using you it will then get converted how you expect it to!
Random
There has always been a random number generator since.NET1 (RandomNumberGenerator
). Within .NET Core, this was updated to include the Random
class. Within .NET 8, we have two new methods, GetItems<T>()
and Shuffle<T>()
.
You can use GetItems()
to randomly choose a specified number of items from an input set. The following code looks like this:
Frozen
.NET 8 introduces several new types aimed at improving app performance.
The new System.Collections.Frozen namespace includes the collection types FrozenDictionary
Indexing
IndexOfAnyValues
.NET SDK and Non-Code Things
Asides from code updates there are also a number of proposed framework changes. These include a number to the CLI tool. Whenever you use dotnet publish
and dotnet pack
this will create a build in release
mode.
Native AOT The first NativeAOT features were shipped in .NET 7 and targeted console applications. Ahead-of-Time (AOT) compilation is an important feature in .NET that can have a significant impact on the performance of .NET applications.
If you want to learn more about what's new in .NET there are two great blogs posts created by Microsoft that you can check out here and here