Paul Krill
Editor at Large

Microsoft’s C# 10 promises ‘prettier’ code

news
Nov 10, 20212 mins

Major upgrade to the .NET programming language arrives with new capabilities designed to improve speed and expressiveness.

Binary streams across a row of computer displays.
Credit: Loops7 / Getty Images

C# 10, the latest release of Microsoft’s object-oriented, type-safe programming language for the .NET platform, has arrived, with capabilities intended to make code “prettier,” quicker, and more expressive, the company said.

The upgrade to C# is part of the .NET 6 software development framework and Visual Studio 2022 IDE, both of which were published as production releases on November 8.

New features and improvements in C# 10 include the following:

  • The C# 10 compiler understands code better and produces fewer spurious errors. Developers will see fewer spurious errors and warnings for null references.
  • C# using directives simplify how to work with namespaces. In C# 10, a global using directive and implicit usings reduce the number of usings needed to be specified at the top of each file.
  • Implicit usings, enabled in .NET 6 templates, add common global using directives for the type of project being built. To enable implicit usings, developers must set the ImplicitUsings property in the .csproj file.
  • Namespaces can be included as a statement, followed by a semi-colon and without curly brackets.
  • Improvements have been made to types and syntax surrounding lambdas. Lambda expressions now have a “natural” type, meaning the compiler often can infer the type of the lambda expression.
  • Attributes can be put on lambda expressions in the same manner as methods and local functions.
  • Improvements to structs provide better parity between structs and classes. These features include parameterless constructors, field initializers, record structs, and withcode expressions.
  • Record classes have been improved. The ToString() method now includes the sealed modifier, preventing the compiler from synthesizing a ToString implementation for derived records.
  • with expresions are supported for all structs including record structs and anonymous types.
  • The syntax for interpolated strings has been improved for performance and expressiveness.
  • Property patterns have been extended to make it easier to access nested values in patterns.
  • Static members in interfaces can now be declared as abstract, providing the basis for a new set of generic math constraints that enable developers to abstract over which operators are available.
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