C# team looks for feedback on parameter null-checking and list pattern features


With Visual Studio 17.1 being available, developers with a knack for C# programming now also have access to a preview of the first couple of features planned to make it into C# 11, which should drop some time in November 2022.

The highlights of the current preview come in the form of implementations of a list pattern and parameter null-checking. The C# team decided to include the latter early in the process, since the design phase wasn’t without its bumps and feedback is needed to ensure it can be used as intended and without causing any grievance. 

Parameter null-checking was introduced as a simple way of validating that method arguments are not Null and throw the corresponding exception. The feature was inspired by the recent work on nullable reference types and looks to make sure devs know early whether nulls are passed to code. 

It can be used by positioning the bang-bang operator (!!) after the name of an item in a list of parameters, though this won’t work with parameters without implementation, extern method parameters, delegate parameters, and interface method parameters with non-DIM methods. The C# compiler will then take the !! as the sign to then generate Null checking code, but also issue a warning should the !! syntax on parameters be combined with an explicitly nullable parameter type.

List patterns have meanwhile been added to offer a capability to match arrays or lists with a sequence of patterns. The syntax for the list patterns (the part used to match elements) are values surrounded by square brackets, while its two dots for the also new slice pattern, which can be used to discard or capture zero or more elements. To get hold of the content of a slice, the slice pattern can be followed by another list pattern.

Other than that C# will become a tiny bit easier to write, as new-lines in interpolations are allowed starting with the current preview. Developers who have missed a way of creating string literals with arbitrary text in C# should wait for the next VS update, as version 17.2 is promised to include an implementation of raw string literals. More improvements are still in progress, though an addition to use cache delegates for static method group conversions has already been merged for the same release. 

Implementation details can be found in the documentation of the Roslyn .NET compiler used in VS. Developers who want to influence what else should go into the language are recommended to visit the C# repository and contribute to the discussions around the current top proposals there. 

Other members of the C family are growing and thriving as well – only recently, C project editor JeanHeyd Meneide took to Twitter to inform programmers about the latest progress of the language. The next version of the C standard is planned to be ratified in 2023 and is going to include a fundamental type for N-bit integers as well as the implementation of a proposal called “towards integer safety” amongst other things.