Microsoft’s C# 9.0 begins to take shape

Proposed capabilities for C# 9 include simplified parameter null validation, record types, and switch expressions

Having just published C# 8.0 in late September, Microsoft has already begun planning C# 9.0. The next version of Java’s archrival could gain switch expressions, record types, and simplified parameter null validation code, among a multitude of other capabilities.

With the C# language being open source, Microsoft expressed it is working with the community to propose features for the next version. The project’s GitHub page has not cited a serious arrival date for the upgrade, just saying it was due by January 1, 2090.

Among the capabilities eyed for C# 9.0 thus far include:

  • Simplified parameter null validation code, allowing for standard null validation on parameters to be simplified using a small annotation on parameters.
  • Support for a switch expression as a statement expression when every arm’s expression is also a statement expression. No common type among the arms is needed when used as a statement expression.
  • Records, a simplified declaration form for C# class and struct types combining benefits of similar features. Records provide a mechanism for declaring a datatype by describing members of the aggregate as well as additional code or deviations from the usual boilerplate, if any.
  • CallerArgumentExpression, enabling developers to capture the expression passed to a method, to allow better error messages in diagnostic/testing APIs and reduce keystrokes.
  • Relaxing of ordering constraints around “ref” and “partial” modifiers on type declarations.
  • Primary constructors, to reduce programming overhead by putting constructor arguments directly in scope throughout a class, obviating the need to explicitly declare a backing field.
  • Top level statements and member declarations, embracing a scripting dialect within C#. The C# compiler currently understands a dialect of the language used for scripting and interactive purposes. Use of the scripting dialect has been relatively minor but usage is picking up. The plan is based on a belief that extensions to C# could be added to the language rather than having a separate scripting dialect.
  • Support for covariant return types, allowing an override method to have a more-derived reference type than the method it overrides.
  • Static delegates, providing a lightweight callback capability to the language.
  • Support for a nullable-enhanced common type, countering a current situation where current common-type algorithm results are counter-intuitive. With the proposed change, an expression such as condition 7 1 : null would result in a value of type int?code.
  • Permitting ternary operation with int? and double operands.
  • To avoid capturing any local state when supplying lambda functions for method arguments, the lambda declaration would be prefixed with the static keyword. This makes the lambda function like a static method.

C# is an object-oriented and type-safe programming language with roots in the C family, similar to Java. It also supports garbage collection and component-oriented programming, leveraging self-contained, self-describing packages of functionality.

Join the newsletter!

Or

Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.

More about GitHubMicrosoft

Show Comments
[]