Welcome to the 94th Edition of The Catch Block!

In this edition: C# introduces a new operator, and it proves surprisingly controversial.

A LEGO minifigure, wearing a firework costume, which reads "BANG".
We need two of these. Photo by Hello I'm Nik / Unsplash

Plus: .NET's 20th; immutability; the CUPID principles; CancellationToken; and a practical guide to Dapper.

All About The Bang-Bang (!!) Operator in C#

C# is adding a brand-new operator, !! (pronounced "bang-bang"), as a shortcut for throwing an ArgumentNullException in a method call. But, surprisingly to me, this addition to C#'s operator set has caused some controversy. Let's explore why MS might add this operator, what it replaces, and why it's controversial.

NOTE: At time of publishing the !! operator is a preview; it has not been included in the official C# feature set, though the plan is to include it in C# 11. A preview of this feature has been rolled out to the runtime. You can read the proposal for !! here:

csharplang/param-nullchecking.md at main · dotnet/csharplang
The official repo for the design of the C# programming language - csharplang/param-nullchecking.md at main · dotnet/csharplang

The Use Case

I'd be willing to bet that there is a ton of C# code out there that looks like this:

public void MyMethod(string param1)
    if(param1 is null)
        throw new ArgumentNullException("param1 is null!");
    //Rest of implementation

Checking for null is one of the more basic things we do in C#, and until now the best way to do it has been some version of the above: explicitly check for null, and throw ArgumentNullException or some other kind of exception when we find it.

This article is for paying subscribers only

Sign up now and upgrade your account to read the article and get access to the full library of articles for paying subscribers only.

Sign up now Already have an account? Sign in