P M A J E W S K I

Please Wait For Loading

.NET 8 – a worthy successor to .NET 6? - Software Developer's Tour

    You Are Currently Here!
  • Home
  • News.NET.NET 8 – a worthy successor to .NET 6?
.NET 8

.NET 8 – a worthy successor to .NET 6?

Hi! 

Today, I’d like to discuss the news about .NET 8. As you may know, .NET 6 will reach the end of support on November 12, 2024, and the next LTS version will be .NET 8.

.NET and .NET Core release lifecycle
https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core

What is the best feature in C# 12?

For me, the absolute best feature is definitely the one called “Collection Expressions”.

In C#, the syntax for creating arrays has been made similar to that of Python or JavaScript.

Take a look at the syntax below.

As you can see, there’s no need to use new keyword before array initialization.

When is it useable in real code?

Pass argument as array to function old way
Old way to pass single variable as array

VS

New way to pass single variable as array

The second option seems better, doesn’t it?

Rule for your IDE (IDE0300)

This rule prefers new syntax and IDE will show you probably well known light bulb suggestions.

You can read more about it on 

Use collection expression for array (IDE0300)

What other interesting changes are there?

I want to talk about breaking changes between .NET 6 and .NET 7.

First, the code

https://learn.microsoft.com/pl-pl/dotnet/csharp/whats-new/breaking-changes/compiler%20breaking%20changes%20-%20dotnet%208

It looks very complicated, but after spending some time, it looks easy. The title of this is

Previously, when we executed the M method with the ref i argument as M(ref i), the first matched method was the extension method with the ref int i parameter in line 11.

Now in .NET 8 we are allowed to pass ref arguments to function with in parameters. That means when we execute M(ref i) the first matched method will be instance method in class C.

Why do I consider this change to be rather significant?​

I believe that changing the outcome of previously written code is very risky. While this is an extreme case for the problem being described here, if the functionality relying on the above scheme hasn’t had tests written for it, the application’s behavior may become unpredictable in certain cases.

Is that all?

Of course not, C# 12 introduces more interesting things like FrozenDictionary or FrozenHashSet and more, but that’s for another time.

Want to know more?

2 Comments

leave a comment