はつねの日記

Kinect, Windows 10 UWP, Windows Azure, IoT, 電子工作

I started ".NET 5"

This entry is an English translation of the ".NET 5始めました! - はつねの日記" entry

[en]NET 5 has been released.

dotnet.microsoft.com
Even if you don't download the SDK or anything else separately, Visual Studio 2019 will also update to 16.8.1, which is a form of development environment that includes .NET 5.
Therefore, if you are starting out with .NET 5, we recommend that you update Visual Studio 2019 rather than downloading it individually.
Now you have a choice between .NET Core 2.1 LTS / .NET Core 3.1 LTS / .NET 5.
And if you want to create in WPF, you can use .NET Core 3.1 LTS or .NET 5.
Let's pick out some of the most interesting changes in .NET 5.

C# 9.0

In .NET 5, C# 9.0 is available.
C# 9.0 の新機能 - C# ガイド | Microsoft Docs

Top-level statement

From now on, if you want the console to say "Hello World!
>> "Hello World!
System.Console.WriteLine("Hello World!");<< "Hello World!

**

If you want to initialize a variable at the same time as declaring it, you have to write the type name on the right and left side of the equalizer in the same way, for example, if you cannot use var.
From now on, you can write only the left side and the right side can be written as "new()" without the type name. Simple.

private List _observations = new();
_observations = new();
This is because the left side is omitted, it feels the same as var, so my personal opinion is that I would have been happier if the type name on the left side was omitted.

The changes when creating a WPF app

WPF SDK (Microsoft.NET.Sdk.WindowsDesktop) has been changed to .
Sdk. If you do not change, you will see a compile-time warning.
If you have changed the target of your .NET Core 3.1 project to .NET 5, you can use the csproj file to create a .
>> The
Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"

Where the
>> The
Project Sdk="Microsoft.NET.Sdk"