One of this year’s most anticipated developments is C# 9, which will rejoice the programmer community with new, exciting features. Even though there are no concrete facts or declarations about which features will be incorporated in the final release, we can already talk about the most popular proposals based on this GitHub list of Language Version Planning for C# and the feature ideas suggested by the community.

In this article, we are going to introduce and detail the 5 most anticipated features of C# 9, which are the following:

  1. Simplification of Parameter null validation
  2. Primary constructions
  3. CallerArgumentExpressions
  4. Target-Typed “New”
  5. Discriminated Unions

Let’s explore them one by one!

Simplification of Parameter null validation

Writing countless null checks can be tedious. Moreover, building lines of if statements with nested exceptions are not at all aesthetic. However, the simplified null validation proposal would allow coders to eliminate the need for explicit null checking by adding the “!” operator to the parameter, which will trigger the C# compiler to give off a standard “null” checking code. This feature would potentially make the argument validation visible to upstream callers via IntelliSense. Read more details about this code enhancement proposal.

For example:


Primary constructions

Another handy proposal, which has been the topic of discussions since the release of C# 6, is the idea of primary constructions. This feature would allow programmers to make class constructions simpler just like in TypeScript, Kotlin, and other languages. Primary constructions would aim to reduce the overhead by putting constructor arguments directly in scope throughout the class.

For instance:

Code without Primary constructions:

Code with primary constructions:

This method would result in a significantly shorter code, which also decreases the possibility of code-breaks and errors, as the code you don’t have to write won’t break. Furthermore, by eliminating redundant boilerplate code developers would be able to make their code files easier to skim through. Not to mention that these solutions ease their job when it comes to uncovering bugs.

CallerArgumentExpression

The new CallerArgumentExpression feature would come to your help in C# 9 when an assertion or an argument validation fails. When something like this happens, all coders want to know in as many details as possible where and why it occurred. However, in the current stack trace, with the use of Debug info in the code, it is only the file name, the line number, and the method number that is given to them, which is most of the time not enough to tell the assert that failed.

This is why the C# community proposed the CallerArgumentExpression to be included in the new C# 9 release. This would allow the caller to project the expressions passed in at a call site as a string. When using this solution, the constructor of the attribute will need to pick a string argument that specifies the name of the argument in order to project it as a string, in other words, to stringify it.

Developers could add the CallerArgumentExpression to Debug.Assert as follows, to get the requested information:

Target-typed “New”

One of the proposals of C# 9 would give a new, focused and time-saving usage for the word “new”. In the case of new type-targeted expressions, where you already know the type, you could totally forget about the type specifications for constructions. Since the type of expressions is already known, this new “New” would allow you to simplify their usage by entering “new()” instead of “new Dictionary<string, list<string="">>()”.</string,>

Discriminated Unions

“Enum class”-es are a new kind of type declarations. They are usually referred to as Discriminated Unions, due to the fact that they list every single instance type, while the instances do not overlap with each other. To put it differently, discriminated unions are a great solution to define types that encompass any number of dissimilar data types. They are used to enumerate different values.

At the moment C# does not fully support discriminated unions, only via inheritance and some extent of overloading, though having concise and seamless support for these declarations should undoubtedly exist in this programming language, according to the majority of C# developers.

Conclusion

All things considered, it looks like C# gains its popularity by adapting to the requirements of developers and by making learning and adaptation easier for those programmers, who do not specialize in a single programming language. The 5 new feature proposals mentioned above clearly show the way how C# intends to support more functional programming techniques. These improvements make the life of developers easier, while they increase the number of the programming language’s fanbase.


Disclaimer:

Please note that the above-mentioned features are not guaranteed to be part of the new C# 9 release, though it is great to be on top of IT news and follow the course of the development.

It has not been revealed when the release will roll out. One thing's for sure, though: a major Visual Studio update will be needed for it.

Our Blog

June 21, 2019
Is outsourcing right for you?
5 Min Reading time

It’s true - we think outsourcing works. It’s also true that we’ve got a vested interest! We offer top quality outsourcing to clients all over the world. However, that doesn’t mean we think outsourcing is right for every company or for every project.

Allwin

Business
Business
May 24, 2021
Why you should setup your project's CI/CD pipeline ASAP
4 minutes

In IT, the demand for agile application development and faster delivery increases day by day.

Czimer Kristóf

Team Leader
Tech
Tech
June 16, 2021
Why Custom Business Applications Are Inevitable Parts of Your Company's Digital Transformation
6 minutes

By now, you might have been introduced to the term "digital transformation." But what does that mean? For those who still don't have a clear picture, generally speaking, digital transformation is how businesses integrate digital technology into their work, thus changing their business processes, activities, models, and customer relations.

Allwin

Business
Business

További Blog bejegyzések

June 9, 2020
CEO karanténban
3 perc olvasási idő

Ideje levonnunk az elmúlt időszak tanulságait, ráadásul addig amíg még friss az élmény. Ezért május végén beszélgetésre hívtuk Nagy Istvánt, az ALLWIN CEO-ját — szigorúan Microsoft Teamsen —, és arról faggattuk, milyen kihívásokkal kellett szembenéznie vezetőként, illetve hogyan kezelte a cég a hirtelen jött változásokat.

Allwin

Business
Business
June 9, 2020
Hogyan lettem Sitecore MVP?
3 perc olvasási idő

Miért fektet nagy hangsúlyt a közösségépítésre a Sitecore, ami a világ egyik legelitebb CMS (Content Management System, azaz tartalomkezelő rendszer) platformja, és milyen út vezet a közösség MVP elismeréséhez; -erről beszélgettünk Tamással.

Allwin

Business
Business
September 23, 2020
Biztos, hogy intranetet használtok?
3 perc olvasási idő

Gyakran tapasztaljuk, hogy a nagyvállalatok abban a tudatban élnek, hogy van belsős rendszerük, de mindez javarészt a különféle fájlmegosztó és -kezelő felületek vállalati használatában merül ki. A SharePoint alapú vagy Drive megoldások nagyon népszerűek, de ezek alapvetően dokumentumkezelő és projektmunka támogató rendszerek, így senki sem várhatja el tőlük, hogy valódi üzleti megoldásokkal szolgáljanak.

Allwin

Tech
Tech