20

Microsoft unveils C# 11 list patterns, raw string literals

 2 years ago
source link: https://www.infoworld.com/article/3651509/microsoft-unveils-c-11-list-patterns-raw-string-literals.html
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.

Microsoft unveils C# 11 list patterns, raw string literals

Next version of Microsoft’s flagship programming language for .NET development will also simplify the syntax for parameter null checking.

By Paul Krill

Editor at Large,

InfoWorld | Feb 24, 2022 3:00 am PST

C# 11, the planned next generation of Microsoft’s object-oriented language for .NET software development, is beginning to take shape, with new capabilities including list patterns and raw string literals.

Preview features for C# 11 can be found in Visual Studio 2022 17.1 and .NET SDK 6.0.200, and raw string literals in a preview of Visual Studio 2022 17.2. C# 11’s list patterns let developers match against lists and arrays. Developers can match elements and include a slice pattern that matches zero or more elements. With slice patterns, developers can discard or capture zero or more elements.

[ Also on InfoWorld: Programming the Windows kernel with eBPF ]

Raw string literals let developers convert a normal or verbatim string literal to a raw string literal. This new form of string literal starts with a minimum of three """ characters (but no maximum), followed optionally by a new_line and the content of the string, and then ends with the same number of quotes that started the literal.

If C# 11 follows the pattern of its predecessor C# 10, which was released in November as part of .NET 6, then C# 11 would arrive this November as part of .NET 7. Also in C# 11, parameter null checking would provide a simplified syntax for validating that method arguments are not null and throwing ArgumentNullException appropriately. Another change eyed for C# 11 would be allowing newlines in the “holes” of interpolated strings. This programming improvement would make legal a situation that currently would result in a compiler error in C# 10.

0 seconds of 21 minutes, 50 secondsVolume 0%
Loading ad

Microsoft is listing proposals for future C# features in the CSharpLang repo. The company also provides a language feature status page in GitHub. Developers are encouraged to check out the C# 11 preview features either through Visual Studio or in the latest .NET SDK and setting the LangVersion to Preview.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK