C# 11 New Features

C# Features

C# 11

C# is an object-oriented, component-oriented programming language.C# provides language constructs to directly support these concepts, making C# a natural language in which to create and use software components.

Now .Net 7 Preview 1 was released on February 17,2022 and along with it, previewed some of the new features in C# 11.

You must set LangVersion to preview to enable these features. Any feature may change before its final release. These features may not all be released in C# 11. Some may remain in a preview phase for longer based on feedback on the feature.

Every developer can check them on their own in Visual Studio 2022 version 17.3 (some of those features are available in earlier VS versions – e.g., Visual Studio 17.1). New features can also be checked in the .NET 7 SDK preview format (available to download on the .NET platform).

  • Generic Attribute
  • NewLine in string Interpolation
  • Parameter null-checking
  • List and Slice Pattern

Generic attributes

C# version 11 has been equipped with a generic attribute feature. This allows you to create a generic class deriving a System.Attribute, which facilitates creating attributes requiring System.Type parameter. In earlier versions of C#, a developer had to construct a more complex solution of attributes with the Type parameter in the constructor.

NewLine in string Interpolation

String interpolation was introduced in C# 6 with Visual Studio 2015. String interpolation replaces String.Format(). The format of the interpolated string is a string inside double quotes preceded by $. Inside that string, you can pass the parameters or method executions in brackets {}.

In C# 11, string interpolation gets a small update – it allows you to contain new lines inside the formulas. Previously, some long formulas, containing LINQ queries might have been unreadable. But no more! With the next release of C#, we will be able to use new lines, and then, complex string interpolated formulas will look much better.

Parameter null-checking

They are putting this feature into this early preview to ensure we have time to get feedback. There have been discussions on a very succinct syntax vs. a more verbose one. We want to get customer feedback and from users that have had a chance to experiment with this feature.

List and Slice Pattern

Pattern match has been evolving over the past couple of versions of C# and it continues to do so in C# 11 as well. List Pattern and Slice Pattern are the new entrants in the pattern collections which are getting richer with each C# version.

Comments

Popular posts from this blog

Angular 15 Update Upcoming

ChatGPT

Azure Cosmos DB