C# 12 updates
A couple of weeks ago Microsoft has released C# 12 which packed a lot of new features. In the upcoming weeks I'll be diving into these update and writing about it.
A couple of weeks ago Microsoft has launched C# 12 which packed a lot of new features (Microsoft, 2023).
If that’s not a reason to start diving into the new C#-features, I don’t know what is. The best part about this update, at least to me, is that there are some concepts of which I’m not quite sure what they actually are, or even why I would want to use them in the first place.
That’s why I’m starting a small series on the C# 12 features that I want to deep dive into, learning about the concepts, figuring out how to implement it and figure out what the use-cases are.
Setup
For my own sanity and redelivery purposes, I’ll be going over the environment I’ve setup for the dive into C# 12. I’ll be using .NET 8, because it’s the latest LTS release.
If you already have a working environment, feel free to ignore this section completely.
Install .NET 8
Before I can dive into .NET, I have installed it using Homebrew on macOS.
$ brew install dotnet@8
*Note the @8 is not required since the latest version of the formula is already 8. But for repeatability’s sake, I’ve included it.
Set up the solution
All features will be added as a project to the csharp-12-features solution on github.com/bartkessels/dotnet-8-features.
The solution is created using the .NET cli.
$ mkdir csharp-12-features
$ cd csharp-12-features
$ dotnet new sln
And now the projects where each feature will live, this step assumes you’re still in the csharp-12-features folder from creating the solution.
$ dotnet new console -n ProjectName
$ dotnet sln add ProjectName
*Note each project will be a console project because it’s pretty assumable that something is going to be printed to an output.
Posts in this series
C# 12 updates - Primary Constructor
For those of you coming for Javascript or Kotlin, you're going to love this new feature. Set your member variables through a primary constructor.
C# 12 updates - ref readonly
In C# 12, Microsoft has added the ref readonly parameter modifier.
C# 12 updates - Default lambda parameters
In C# 12, Microsoft has added the ability to specify default values for your lambda parameters.
C# 12 updates - Collection expressions
C# 12 finally introduces some new syntactical suger that I'm eager to use in production because it improves the readability of the code.