---
title: "C# vNext - What could come"
description: "C# 11 is in front of our doorsteps. A lot of the features are know, so let us have a look at the future.\nWe will discover some features which could be included in C# 12 or later.\n\nBase for this is the [**csharplang**-repository](https://github.com/dotnet/csharplang). So let's discover brand new features and how they could help us in our everyday life. We will see things like:\n * Compound assignments in object initializer\n * Discriminated unions\n * semi-auto properties aka `field`\n * `ConfigureAwait(false)` on assembly level\n * Exponentiation operator"
updated: 2022-06-30
tags: ["C#"]
canonical: "https://steven-giesel.com/blogPost/d502edb0-331a-4041-b491-b4a907ddcc1e/c-vnext-what-could-come"
---

# C# vNext - What could come

In this blog post we will make a small excourse to new features which might come in the close or distant feature of the C# language. The base for all of this is the [**csharp**-repository](https://github.com/dotnet/csharplang). The repository contains proposals as well as inactive or rejected ideas. The markdown files are only half the truth. I'd recommend you to checkout the issue tracker to see how a feature evolved over time. Let's dive right in:

## [Compound assignment in object initializer and with expression](https://github.com/dotnet/csharplang/issues/5176)
The idea behind this proposal is to make object initializer a bit more versatile. In its current state you are only allowed to have simple assignments like that:
```csharp
var timer = new DispatcherTimer
{
    Interval = TimeSpan.FromSeconds(5);
};
// We have to define the lambda function outside of the object initalizer
timer.Tick += (s, e) => { ... };
```

The proposal exactly wants to tackle that behavior: 
```csharp
var timer = new DispatcherTimer
{
    Interval = TimeSpan.FromSeconds(5);
    timer.Tick += (s, e) => { ... }; // This is now allowed
};
```

The same for the `with` expression, where you can directly make compound assignments:
```csharp
public record Person (string Name, int Age);

var steven = new Person("Steven", 30);
var stevenButOneYearOlder = steven with { Age += 1; };     
```

The main benefiter from this request would be a lot of UI frameworks where event-wiring is key.

Source: https://github.com/dotnet/csharplang/issues/5176

## [Discriminated unions](https://github.com/dotnet/csharplang/issues/113)
Using discriminated unions seems a bit weird for an OOP language, but still there are valid uses cases. Let's just check shortly what **discriminated unions** are. For that I'll showcase some Typescript code.
```typescript
interface Cat {
  weight: number;
  whiskers: number;
}
interface Dog {
  weight: number;
  friendly: boolean;
}
let animal: Dog | Cat;
```

The first thing to understand is, that it is not about the common subset between dog and cat. You can better understand this as `animal` has to be either `Dog` or `Cat`. But not only that you could also derive from `Dog` and make a `ShibaInu : Dog` class, which fulfils the requirements.

Source

With that you can do stuff like this:
```typescript
if ("friendly" in animal) {
  console.log(animal.friendly);
} else {
  console.log(animal.whiskers);
}
```

Of course to keep it short, I'll just provide you some links to get a better understanding what a **discriminated union** is and what the usage is. So [here](https://css-tricks.com/typescript-discriminated-unions/), [here](https://blog.logrocket.com/understanding-discriminated-union-intersection-types-typescript/) and a very beautiful example [here](https://stackoverflow.com/a/60480731).

Source: https://github.com/dotnet/csharplang/issues/113

## [`field` keyword - semi auto-properties](https://github.com/dotnet/csharplang/issues/140)
This one might even come with C# 11. There is a strong indication because there is a feature branch in the roslyn repository which does translate that keyword correctly. I swear a few days ago even on `main` it worked but they seemed to remove it.

The idea is to make auto-properties even better in the sense that you need less code in some scenarios.

In the current world we have that (C# 10):
```csharp
public class MyClass
{
    private string _myString;
    
    public string MyString 
    { 
        get => _myString;
        set => _myString = value ?? throw new ArgumentNullException;
    } 
}
```

With the new `field` keyword it looks like that:
```csharp
public class MyClass
{
    public string MyString 
    { 
        get => field;
        set => field = value ?? throw new ArgumentNullException;
    } 
}
```
The compiler does automatically create the backing field for us. No need to explicitly use it. We have the full control via the `field` keyword to use it. 

Source: https://github.com/dotnet/csharplang/issues/140

## [`ConfigureAwait(false)` on assembly level](https://github.com/dotnet/csharplang/issues/2542)
The next one is a small helper. Basically when you write a library which handles async code the norm is to use `await SomeAsyncOp().ConfigureAwait(false);`. So this `ConfigureAwait(false)` stuff will be everywhere because this is what you want as a library maintainer. The proposal would tackle that in the sense, that you can specify via assembly attribute that the compiler should automatically add `ConfigureAwait(false)` on every `await` call.

Source: https://github.com/dotnet/csharplang/issues/2542

## [Exponentiation operator](https://github.com/dotnet/csharplang/issues/2585)
JavaScript / TypeScript has it, Python has it, F# has it and even VB.NET has it: The **exponentiation operator**.
Often times like this: `**`. So instead of `var number = Math.Pow(4, 3);` you can simply write: `var number = 4 ** 3;`. You could ask, is this really better? And I want to quote [Jeffrey on the issue tracker](https://github.com/dotnet/csharplang/issues/2585#issuecomment-273681701):

> Exponentiation is no different from addition or multiplication: it is a common mathematical operation for which there is a universal notation (including precedence rules) that is approximated in programming languages.

This feature would also go really good with the new [**generic math**](https://devblogs.microsoft.com/dotnet/dotnet-7-generic-math/) feature.

Source: https://github.com/dotnet/csharplang/issues/2585

## Conclusion
5 nice features. Is there any of those you want to have rather yesterday than in an upcoming version? Let me know. And also let me know if I missed a crucial proposal.