As one of my languages du jour, I've always had a fondness for C#. It was one of the first high-level languages that I learned in college and it's been part of my daily professional life for the better part of ten years. One of the things that's always been enjoyable about the language is the concept of constant innovation.
Features are constantly being adapted from other languages (looking at you F#, Kotlin, Typescript, and more) to help add features that would be greatly desired, extend existing functionality, or just apply an ample sprinkling of syntax sugar. So I thought with the new year just beginning, let's take a look at some of the proposed features that are slated to find their way into the flagship Microsoft language in the near future!
It's worth noting that this is by no means a complete list and everything in this list, as with all things in active development, is subject to change / never happen.
So, let's get into it!
Your Results May Covary
Have you ever been writing a class and found yourself just inventing new methods so that you can return some type from a base class since C# has always restricted you to only return the explicit class itself? This proposal outlines what would be support for covariant return types, which would allow you to override an existing method using a more specific implementation than the original method.
- class Animal
- {
- virtual Animal GenerateFromEnvironment(EnvironmentConfiguration config);
- }
Now previously, if you wanted to extend your Animal class to support something like a Dinosaur, you'd have to either write some hacky bridge method or throw some logic in there to specifically check for the existence of a Dinosaur. Covariant returns will allow you to still override the same base class / methods, but return the more specific implementations you are looking for your class:
- class Dinosaur : Animal
- {
- // Notice the more specific return type overriding the virtual method
- override Dinosaur GenerateFromEnvironment(EnvironmentConfiguration config);
- }
Support for this feature does not require the targeted class to implement the IDisposible interface, but instead just contain a Dispose() method.
A "New" New
Often the var keyword can be great if you don't want to go to the effort of explicitly defining a type for a variable. You already know what it's going to, so it's convenient to just keep things short. This proposal follows that same rough premise by introducing a new usage for the word 'new', specifically type targeted new expressions, which allows you to completely forego the type specification for constructors when the type is already know.
Let's say you had some complex collection like the following that you wanted to initialize upon declaration:
- Dictionary<string, List<string>> words = new Dictionary<string, List<string>>() {
- { "foo", new List<string>(){ "foo", "bar", "buzz" } }
- };
- Dictionary<string, List<int>> words = new() {
- { "foo", new() { "foo", "bar", "buzz" } }
- };
Null Checks Kotlinified No More
No one really likes writing countless null checks. Lines upon lines of if statements with nested exceptions being thrown, it's gross. In a vein similar to the previous feature, this proposal aims to eliminate the need for explicit null checking by allowing an operator ! to be added to a parameter to indicate to the compiler that a given value will not be null.
It would transform a snippet like the following,
- // Before
- int CountWords(string sentence)
- {
- if (sentence is null)
- {
- throw new ArgumentNullException(nameof(sentence));
- }
- // Omitted for brevity
- }
Into a much terser, uncluttered form,
- // Notice the trailing '!' after the parameter name, which indicates
- // it will not be null
- int CountWords(string sentence!)
- {
- // Omitted for brevity
- }
Let the Constructor Do the Work
Another proposal that has been or in some phase of discussion since C# 6 has been the idea of primary constructors, a feature that's been found in languages like Typescript, Kotlin, and other languages. The basic idea behind primary constructors is that they would simplify writing class constructors and boilerplate code in general by implicitly creating private fields from the arguments passed in by the constructor itself.
Let's look at an example of a class with a few private, read-only properties,

Rajanikant HawaldarPosted Jan 6, 2020, 10:47 PM
Thanks Rion Williams for sharing
knguyen_03Posted Jan 3, 2020, 10:06 AM
Why are new versions of C Sharp increasingly looking like Voodoo language?
Raju PaladiyaPosted Jan 2, 2020, 11:46 PM
Nice one! Thanks for share.
Amit MohantyPosted Jan 2, 2020, 11:19 PM
Nice article
Chittaranjan SwainPosted Jan 2, 2020, 4:56 AM
Nice article thanks for sharing.
Goutham KsPosted Jan 2, 2020, 3:03 AM
Pretty nice stuff...Thank you for sharing Williams
Ankur MistryPosted Jan 2, 2020, 1:19 AM
Useful stuff thank you for sharing
Sourav Kumar DasPosted Jan 2, 2020, 1:12 AM
Nice and useful article Sir.