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.
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?
VS
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
What other interesting changes are there?
I want to talk about breaking changes between .NET 6 and .NET 7.
First, the code
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?
Visit What’s new in C# 12
Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! However, how can we communicate?
[…] A while ago, we talked about the new features introduced in .NET 8 – a worthy successor to .NET 6? […]