Discover .NET 5 Through 5 New Features and a Vision of the Future

Chris J.
Chris J.
Nov 26, 2020 · 5 min read
.NET 5 : 5 new features… and M1 ?
.NET 5 : 5 new features… and M1 ?

.NET 5 hit the developer world a few days ago. One of the most major evolutions in the framework’s history, it confirms Microsoft’s strategy in terms of open-source and cross-platform development.

In fact, most of the features of this new framework were either developed, enhanced or suggested by the passionate .NET community. This drives Microsoft into building better products, responding directly to their users needs.

With .NET 5, they unified .NET 4.6 and .NET Core into a single vision for .NET. Their goal is to use the same platform in order to build any kind of dynamic application.

Literally any kind. From mobile and desktop apps (Xamarin/WPF), to front-end web development (Blazor), including REST (ASP.NET), gRPC and web sockets (SignalR). Oh, and they also have machine learning (ML.NET) and quantic programming (Q#).

Now, really, what’s new in .NET 5 ? Why is this going to change the lives of thousands of .NET developers ? What’s next in .NET 6 ?

That’s what we will find out.

Records

Image for post
Image for post

Records are a feature that’s actually borrowed from Kotlin and its data classes.

Records are basically classes that behave like a reference type, which means there is no copy when you pass them as parameters to your member functions.

But they also behave like a value type in a sense that they implement a default member equality.

Records and their default member equality. Carapuce is French for Squirtle 😉

That means you don’t have to implement yourself when you want to compare reference types. Now, that’s time saving!

With records, there’s also a new keyword that permits you to specify values to fresh copies of records with a new fancy syntax.

Building a Squirtle from a Charmander. That’s unheard of !

Records are perfect for people working with data. The flexibility of a , and the pragmatism of a . What a beautiful baby !

Also, I’ve been testing records with Dapper and it works like a charm.

Pattern matching improvements

Image for post
Image for post

C#9 introduces new keywords , and .

Combined with a new syntax you can do things like this:

A straightforward way to compare values of strings.

You see, in the above example, you compare the string with the constants and empty string. This replaces the tedious use of .

You can also check if something is not by writing a code like this:

Even your neighbor can understand your code now.

And it also works with numbers, and inside expressions for more advanced use cases. But I’ll let you experiment that by yourself.

Top-level programs

Image for post
Image for post

With that feature, C#9 almost becomes a scripting language just like Python.

Just like this, you can basically write C# code outside of the scope of a method or a class.

Yes, the above C# code compiles with a simple .

This is very good for C# beginners, and can be useful for Unity developers, manipulating C# scripts all the time.

I’m curious about the future advanced uses of such a feature. I see that as a replacement to the use of function for configuration code. Typically while configuring a for ASP.NET.

This will allow C# developers to publish microservices that consists of just one C# file. That can be time saving for proof-of-concept apps or small apps like a chatbot or an AWS Lambda.

Json Enhancements

Image for post
Image for post

Now let’s talk about the framework itself. With .NET 5, has been replaced with .

By doing that, Microsoft makes the .NET framework more independent and closely tied with framework evolutions.

In fact, that JSON framework migration had already started with .NET Core 3.1. With .NET 5, that evolution anchors itself even more into the framework with performance improvements and feature enhancements.

Such migration can also break existing code, as the engine of ASP.NET Core 2.0 was based on . Be careful when you migrate, especially if you used . It’s now being replaced by .

Docker

Image for post
Image for post

When we think about ASP.NET deployed in the cloud, it is common to think about Docker. With .NET 5, Microsoft removed a build pack dependency called .

By doing that, they could decrease the docker image file by 40% on Debian Linux.

Just take a look at the below chart. That’s very good news.

Image for post
Image for post
Docker whale was on a diet for a while.

This basically means that every will be faster, resulting in faster deployments. Gotta go fast !

.NET 6 … and Apple Silicon ?

Image for post
Image for post
The announcement of the M1 chip (© Apple)

Finally, I want to talk about the next release of .NET, which is .NET 6.

As you may know, Apple announced in november new Mac computers with their own processors based on the ARM architecture. These processors are called M1. Their main advantage is that they are blazing fast compared to their Intel counterparts.

But transitioning to a hardware that’s so different from Intel infers that the software has to adapt to it. A thing that Microsoft didn’t do with .NET 5. Yet.

In this next release, Microsoft announced via a GitHub project that they will enable .NET support on Macs with Apple Silicon.

I personally think that this move is crucial for Microsoft, as it is a needed step to build a solid cross-platform development ecosystem.

The Startup

Medium's largest active publication, followed by +755K people. Follow to join our community.

Chris J.

Written by

Chris J.

Passionnate Software Engineer. Back-end and cloud specialist. iOS & Cocoa Engineering enthusiast. Also I’m a teapot.

The Startup

Medium's largest active publication, followed by +755K people. Follow to join our community.

Chris J.

Written by

Chris J.

Passionnate Software Engineer. Back-end and cloud specialist. iOS & Cocoa Engineering enthusiast. Also I’m a teapot.

The Startup

Medium's largest active publication, followed by +755K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store