I’ve been looking at some of the new .NET 6 features that are currently in preview. There are few neat little features that I wanted to share
Minimal API
New ASP.NET projects have barely any “boiler plate” code and removed a lot of the noise away to leave us with only the code that really matters.
We don’t even have a startup / program class, nor a Main()
entrypoint.
DateOnly and TimeOnly
Finally it’s now possible in C# to indicate that we are using “only” dates using DateOnly
without lugging the time along with us.
There’s also TimeOnly
which is slightly different to TimeSpan
since it indicates a time within a day.
Enumerable Chunk
Paging Lists hasn’t been too bad. (Skip
and Top
). Paging Enumerables with yield
returns have been tedious. We need to get the get the enumerator, move through and keep state of items to page / chunk them.
The new Chunk
extension on Enumerable makes this much simpler
Global usings
This is really neat! We can now define some using statements which are repeated in all the classes as global and now we no longer need to define them in each class anymore.
A great way to keep our classes lean.
New LINQ extension methods
LINQ has always been great. Getting some fresh extensions methods makes my day.
Check out these great new extension methods with the ...By
suffix.
e.g. MinBy
& MaxBy
Defaults with defaults
The OrDefault
extenions methods have been great since we haven’t had to do if (extists)
checks before getting an entry.
Even better, we now can define our own defaults rather than having to rely on the data type defaults anymore!
This really is just the tip of the ice berg
These are just a few of the great new features with .NET 6 that stood out for me. There’s a lot more coming with .NET 6.
Also, major .NET upgrade of late comes with a plethora of performance enhancements and optimizations.
Exciting times…