Paul Krill
Editor at Large

Microsoft unveils C# 11 list patterns, raw string literals

news
Feb 24, 20222 mins

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

Spotlights on stage
Credit: Thinkstock

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.

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.

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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author