C# 9 - Oh boy!

C# 9 - Oh boy!

Just seen the following blog post about c# 9 (Shout out to Muhammad Ahsan Shakir for bringing it to my attention):

https://devblogs.microsoft.com/dotnet/welcome-to-c-9-0/

I recently shared a post about the newer features of C# 8 and that I was excited to get started to use them. However some of the new stuff in C# 9 really makes me want to download the preview release and have a good play.

I've not used c# since September (other than minor bits at home). It is a language that I have used quite significantly and have a lot of fondness for.

The features I am looking forward to the most in C# 9:

  1. The "with" statement. In previous roles I have had the benefit (and curse) of working in both VB.net and C# at the same time. One of the main things I missed, when switching between languages, was the "with" statement. Hopefully it won't have the pitfalls with auto complete and source tracing that VB.net had (to my knowledge still has, however I haven't VB'd in a while).
  2. Init only properties. This will make declaring properties for read only fields much easier providing a handy way of making immutable fields! I whole heartedly approve this feature.
  3. Records/Data Classes - Treat classes that are storing data as values instead of objects. After all, its data!
  4. Top-Level programs - Removing a lot of the boiler plate around your main program execution/entry point. This reminds me of how Kotlin changes your Java code!
  5. Targeted Type Expressions - The ability to create new types without specifying the type, as long as it can be inferred from the context. I think this is pretty cool!
  6. Conditional Target Type Comparison - The ability to use ?? to assign a value even if the true and false cases have a different type, as long as they derive from a common type.
  7. Co-Variant Returns - the ability to override a function's return type to a more specific instance of the derived type! I can see this being very useful, however part of me is a little wary of this, putting too much complexity into your inheritance, and potentially leading to code that is too DRY...

There are of course more, but these are the ones I could see myself using?

What does everybody else think? What features do you think you would use the most? What do you think should/should not be in the release?

As always I would love to hear everybody's thoughts on this, and if anybody wants to chat about this (or any other subject) feel free to get in touch!

David Johnson, Senior Software Engineer


To view or add a comment, sign in

More articles by David Johnson

Others also viewed

Explore content categories