C# 12 – Alias any type

The using alias directive has been relaxed in C# 12 to allow aliasing any sort of type, not just named types. This means that you can now alias tuples, pointers, array types, generic types, etc. So instead of using the full structural form of a tuple, you can now alias it with a short descriptive…

What’s new in C# 12

As technology continues to evolve, so does the C# programming language. With the release of C# 12 on the horizon, developers can look forward to a host of exciting new features and enhancements that promise to streamline their coding experience and open up new possibilities in software development. If you haven’t yet switched to C#…

How to switch to C# 12

While trying out C# 12 features, it’s possible you might come across errors similar to these: Feature is not available in C# 11.0. Please use language version 12.0 or later. or Error CS8652: The feature ‘<feature name>’ is currently in Preview and unsupported. To use Preview features, use the ‘preview’ language version. There are two…

C# 12 – Default values for parameters in lambda expressions

Starting with C# version 12, you can specify default values for your parameters in lambda expressions. The syntax and the restrictions on the default parameter values are the same as for methods and local functions. Let’s take an example: This lambda can now be consumed as follows: params array in lambda expressions You can also…

C# 11 – Generic attributes

All right folks, generic attributes are finally a thing in C#! 🥳 You can define one just as you would define any other generic class: And use it like you would use any other attribute: Generic attribute restrictions When applying the attribute, all the generic type arguments must be provided. In other words, the generic…

C# 11 – Raw string literals

Raw string literals are a new format which enables you to include whitespace, new lines, embedded quotes, and other special characters in your string, without requiring escape sequences. How does it work: A quick example: This will output the following: Whitespace before the closing sequence The whitespace before the closing double-quotes controls the whitespace which…