C# 8.x Next Feature Status

In this article, I will describe each feature in C# NEXT Feature Status and demonstrate them with examples.

The milestones C# 8.1 and C# 8.2 were removed from GitHub, probably to prevent speculation on a release date or which features could be released in the next version. We have seen in the last years a lot of new features. That causes a lot of trouble, and it was a big challenge for the .Net developer team. The most problems came from the legacy code or to keep the compatibility between the existing programming concepts and the new concepts.
C# NEXT, as shown below, contains the candidate features for C# 8.1 .. 8.x. Only if the candidate features in the “master” branch, that means the feature will be released in the next version.

Caller Expression Attribute

Allows the caller to ‘stringify’ the expressions passed in at a call site. The constructor of the attribute will take a string argument specifying the name of the argument to stringify.

Target-typed new-expressions

“var” infers the left side, and this feature allows us to infer the right side.
Example

Mads example

Generic attributes

Allows the generic type in the C# ‘Attributes’.

Default in deconstruction

Allows the following syntax (int i, string s) = default; and (i, s) = default.
Example

Relax ordering of ref and partial modifiers

Allows the partial keyword before ref in the class definition.
Example

Parameter null-checking

Allows simplifying the standard null validation on parameters by using a small annotation on parameters. This feature belongs to code enhancing.
Example

Skip locals init

Allows specifying System.Runtime.CompilerServices.SkipLocalsInitAttribute as a way to tell the compiler to not emit localsinit flag. SkipLocalsInitiAttribute is added to CoreCLR.
The end result of this will be that the locals may not be zero-initialized by the JIT, which is in most cases unobservable in C#. In addition to that stackalloc data will not be zero-initialized. That is definitely observable but also is the most motivating scenario.

Lambda discard parameters

Allow the lambda to have multiple declarations of the parameters named _. In this case the parameters are “discards” and are not usable inside the lambda.
Examples

Attributes on local functions

The idea is to permit attributes to be part of the declaration of a local function.
“From discussion in LDM today (4/29/2019), this would help with async-iterator local functions that want to use [EnumeratorCancellation].
We should also test other attributes:”
  1. [DoesNotReturn]
  2. [DoesNotReturnIf(bool)]
  3. [Disallow/Allow/Maybe/NotNull]
  4. [Maybe/NotNullWhen(bool)]
  5. [Obsolete]
Basic Example
Main use case for this feature
Another example to use it with EnumeratorCancellation on the CancellationToken parameter of a local function implementing an async iterator, which is common when implementing query operators.

Native Ints

Introduces a new set of native types (nint, nuint, nfloat, etc) the ‘n’ for native. The design of the new data types is planned to allow a one C# source file to use 32 naturally- or 64-bit storage depending on the host platform type and the compilation settings.
Example
The native type is depending on the OS,

Function pointers

I remember the term function pointer from C/C++. FP is a variable that stores the address of a function that can later be called through that function pointer. function pointer can be invoked and passed arguments just as in a normal function call.
One of the new C# candidate features is called Function Pointers. The C# function pointer allows for the declaration of function pointers using the func* syntax. It is similar to the syntax used by delegate declarations.
Example 1
Example 2

Summary 

You have read about the candidate features for 8.1 and 8.2 and 8.x.