The Community Loves New Features in C# 11
source link: https://devm.io/csharp/c-sharp-11-release
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
10. Nov 2022
Microsoft has announced that the latest version of C# is now available for download. A new version of the programming language is released every year, and the community eagerly awaits each update.
These are the highlights of the latest release:
- Support for generic attributes
You can declare a generic class whose base class is System.Attribute. The feature offers a more practical syntax for attributes that require a System.Type parameter.
- UTF-8 string literals
C# strings are hardcoded to UTF-16 by default, however, the most common string encoding on the internet is UTF-8. If your application needs UTF-8 strings, you can now easily convert your string literals to UTF-8 by adding the u8 suffix to them.
- Raw string literals
The new format for string literals, raw string literals, does not require escape sequences and can contain any text, including embedded quotes, multiple lines, whitespace, and other special characters. C# 11 allows you to create raw string literals by repeatedly using quotation marks.
- List patterns
List patterns extend pattern matching to match sequences of elements in a list or an array.
- Required members
You can now add the modifier required to properties and fields to enforce constructors and callers to initialise those values.
The full list of changes is available here, and the technical documentation on GitHub.
Learn more about C#
Want to know more about C#?
In this article, Rainer Stopek explains how to use C# source generators and discusses what sets them apart from other available code generation options.
Sanja is a Junior Online Editor at Software and Support Media GmbH. She holds a master's degree in English Language and Literature.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK