Forem

Zohar Peled
Zohar Peled

Posted on • Originally published at zoharpeled.wordpress.com

3 2

c#9 is finally here (this is not about init-only or records)

c# 9 and .Net 5 are finally officially released, and everybody blogs about init-only properties and records - which are very exciting and long-awaited features that I'm sure will be used a lot and contribute a lot to code quality.

However, I would like to address another great thing about c# 9 that I didn't see a lot of bloggers excited about - and that is the improvements of pattern matching. Specifically, the adding of the not keyword - as it relates to an older post I've published almost exactly a year ago:


In c# 9, We finally actually do have the perfect non-null test, and it's way better than x is object because it's much, much more readable:
if(x is not null) { /* No explanation needed... */ }
Enter fullscreen mode Exit fullscreen mode

See when I first started using x is object in my code, My team leader have complained that it's less readable than the x != null we had all over our code base. I actually had to convince him that this is a better option. With the c#9 new syntax, anyone reading the code that has even minimal knowledge of c# and the English language can instantly understand it - which finally, makes it truly the perfect non-null test.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (1)

Collapse
 
maulinshah1015 profile image
maulinshah1015

Like

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More