Paul Krill
Editor at Large

C# roadmap: What to expect in Microsoft.Net’s C# 8.0

news
Nov 14, 20183 mins

Index types, nullable reference types, default interfaces, and async streams should improve code quality and make software more flexible over the long term

digital language code
Credit: geralt

Microsoft has fleshed out more details about C# Version 8.0, the next planned major release of the language. C# 8.0 is expected to arrive in 2019, concurrent with the arrival of .Net Core 3.0. Developers can try out language features in betas of the Visual Studio 2019 IDE.

Microsoft said that while most language features in C# 8.0 will run on any version of .Net, there are some that have platform dependencies. Async streams, indexes, and ranges rely on framework types that will be part of .Net Standard 2.1. While .Net Core 3.0, Xamarin, Unity, and Mono will implement the 2.1 version, .Net Framework 4.8 will not. Thus, types required to use these features will not be available when C# 8. 0 is targeted to .Net Framework 4.8. The C# compiler, though, is lenient about types it depends on and will target types with the right names and shapes if it can find them.

Type-related additions to C# 8.0 include:

  • The new Index type, for indexing. An index can be created from an int that counts from the beginning or with a prefix ^ operator that counts from the end.
  • The Range type, which consists of two Indexes, one for the start and one for the end. It can be written with an x..y range expression; developers then can index with a Range to produce a slice.
  • Nullable reference types, to improve code quality, according to the .Net Foundation, which oversees the open source .Net that C# is part of. The feature will add safe reference types in addition to the existing ones that will be called non-nullable. Compilers will warn you when nullable types are dereferenced or when null is values are assigned to non-nullable variable types. The nullable reference type is intended to help developers prevent null reference exceptions. A core of the capability is expressing an intent to be null. The compiler will recognize when something is not null and warn you when you’ve assigned null to a reference that was not declared as null. With the capability, developers get an assist in finding bugs and making them go away.

Other new features planned for C# 8 are:

  • Switch expressions, which present a lightweight version of switch statements, in which all cases are expressions.
  • Target-typed new expressions, in which the type can be omitted when developers are creating a new object and the type is already given from context.
  • Recursive patterns, in which patterns can contain other patterns.
  • An opt-in method to deal with code-breaking behavior.
  • A default interfaces programming capability, so interfaces can be evolve via virtual extension methods. An API author could add methods to an interface in future versions without breaking source or binary compatibility. The feature already is available in languages such as Java.
  • An async streams feature to provide an abstraction that is the asynchronous version of IEnumerable, which is the base interface for nongeneric collections that can be enumerated.
  • Extension everything, to provide a way to define new kinds of extension members. Although it is already possible in C# to define methods that act as instance methods of the extended type, the C# 8 proposal expands this capability by supporting static and instance members.
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