DEV Community

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 Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (1)

Collapse
 
maulinshah1015 profile image
maulinshah1015

Like

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay