C# Future Revealed At Build
Written by Kay Ewbank   
Wednesday, 23 May 2018

A talk by Mads Torgersen and Dustin Campbell at this year's build has given details of what the future of C# will hold, mainly in C# 8. The details come as the latest version of Visual Studio includes initial support for some features of C# 7.3.

Mads Torgersen is Program Manager for C#, while Dustin Campbell is a Program Manager on the Visual Studio team. Their talk at Build 2018 discussed the features of C# 7.3, along with what's coming in the future, including nullable reference types, recursive patterns, and asynchronous streams.

 

 

The support for nullable reference types is intended highlight null-related problems at the development stage, even in existing code. In future, the default for reference variables, parameters and fields will be that they default to be non-nullable. If you want a variable, parameter or whatever to allow nulls, then you tell C# this by putting a question mark after the type name. The example used in explaining this is a name made up of forename, middlename, surname, where forename and surname are non-nullable, but middlename can be null. 

While this will help code going forward, the idea is being introduced cautiously. All enforcement of null behavior will be in the form of warnings rather than errors, and there’s a compiler switch to turn the warnings on or off. The warnings will recognize existing ways of checking for null, and not force you to change your code where you are already diligently doing so.

Recursive patterns is another headline improvement. First pattern matching was added to C# 7, and this will be extended in C# 8 with recursive patterns. A recursive pattern means you can match part of the data against sub-patterns. The proposal for the feature says it will enable many of the benefits of algebraic data types and pattern matching from functional languages, but in a way that smoothly integrates with the feel of C#. A preview of recursive pattern matching is available on GitHub.

In a recursive pattern, if your customer class with Forename, Middlename, Surname also had SalesPerson as part of the class, and SalesPerson also had its own Forename etc, you could use recursive pattern matching to check both surnames.

Ranges are another forthcoming addition that is included in the preview on GitHub.The addition of ranges means that an expression x..y will produce a value of type System.Range.

Ranges offers a number of advantages, including making it simple to extract data, and to be used in patterns to produce simple range checks.

Asynchronous streams was another key improvement highlighted in the talk. Async streams add an asynchronous equivalent of IEnumerable. C# has support for iterator methods and async methods, but no support for a method that is both an iterator and an async method.  Async streams mean that await can be used in a new form of async iterator, one that returns an IAsyncEnumerable<T> or IAsyncEnumerator<T> rather than an IEnumerable<T> or IEnumerator<T>, with IAsyncEnumerable<T> consumable in a new foreach await. An IAsyncDisposable interface is also used to enable asynchronous cleanup.

The talk includes details of other potential improvements, including default interface implementations to allow abstract interfaces to fully define methods just like abstract classes. This idea is still being debated for C# 8, and is generating a lot of discussion.

Alongside details of what might or might not be coming in future versions of C#, Torgersen and Campbell also discussed what the latest version of Visual Studio includes in the way of initial support for some features of C#7.3, including offering more control over the types you pass in to generic functions.

You can now say that the types must be enum, delegate, or blittable types - in other words, a type that has the ability to be sent without changes over the managed-unmanaged boundary to native code because it has no references to the managed heap. This essentially means a type that consists only of certain predefined primitive types (such as int or UIntPtr), or arrays of those types.

Other C# 7.3 support in Visual Studio includes better overload resolution so that compiler errors aren't generated by false matches; stack allocated arrays; and tuple comparisons.

c

More Information

C# 8 Work List of Features

Related Articles

Project Rider A Cross Platform C# IDE

C# Joins PVS-Studio Line Up

C# 7 Features

C# 7 - What Would You Put In?

Visual Studio 2015 CTP 5 Released       

Microsoft Mass Migration To GitHub       

.NET Core The Details - Is It Enough?       

Latest On C# 6 And VB 12

C# 6.0 Features       

C# Gets A New Operator - Safe Navigation

RyuJIT - The Next Gen JIT .NET Compiler

Microsoft tells C# developers to learn JavaScript!?       

Microsoft Team Explains Language Stagnation       

 

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Can C++ Be As Safe As Rust?
10/04/2024

Herb Sutter is a well known and respected C++ champion and he thinks that the language only needs a few tweaks to make it as safe as Rust. Can this be true?



Quantum Computers Really Are A One Trick Pony
17/03/2024

Google is offering $5 million if you can think up a use for a quantum computer. Wait, I thought quantum computers were the next big thing, a revolution! Surely we know what they can do?


More News

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Thursday, 24 May 2018 )