Swacblooms🦋

Making the Moves
Menu
  • Home
  • Motivation
  • Education
  • Programming
  • About
  • Contact
  • Privacy Policy
Home
Uncategorized
C# bang bang operator
Uncategorized

C# bang bang operator

Samson Amaugo April 8, 2022

Hola 🥂🥂, so in the heat of releasing the DotNet 7 preview, developers have been raving about the parameter null-checking operator popularly called the bang-bang (!!) operator😜 in C#.

So let us talk about this feature 🥶

The parameter null-checking is one of the preview features for C# 11. Preview features are features that are still in consideration and might end up making it to becoming default features of the next major release.

Prior to the release of this feature, ArgumentNullException errors could be handled using the various format below:

void Method(string name) 
{
   if (name == null)
    {
        throw new ArgumentNullException(nameof(name));
    }
    // bla bla bla
}

But to try out the bang-bang operator in the c# 11 preview, you need to have at least Visual Studio 17.1 (Visual Studio 2022 Update 1) or .NET SDK 6.0.200.
At the time of writing this post, I am currently using the .NET SDK 6.0.201 to try out this feature.

You can download the SDK by clicking here

Steps To switch Into the preview mode and use the bang-bang operator:-

  • Open the “*.csproj” file >> and add a LangVersion element like the one below
<PropertyGroup>
   <LangVersion>preview</LangVersion>
</PropertyGroup>

  • Now you can use the code below:-
//Now you can you the !! operator
void Method(string name!!) 
{
    /* it would automatically throw the ArgumentNullException error if name is null */
}
// instead of this code 
void Method2(string name) 
{
   if (name == null)
    {
        throw new ArgumentNullException(nameof(name));
    }
    // bla bla bla
}

They have been a little bit of friction in terms of developers in the DotNet community accepting this feature.

Some advocated for the use of a notnull keyword which seems to be more understandable and intuitive at a glance.

To check out more about some of the preview features click this.

Thanks for reading 🥂

PS :- This feature later got removed you can look out for more details here.

Prev Article
Next Article

Related Articles

creating root level files or folders in vscode
Creating a root-level file or folder in vscode can be …

VSCODE Creating Root Level Files or Folders In VsCode

Using youtube like hashes in dotnet
Hola 🦋, so in this post, I would be talking …

Using Youtube-like hashes in DotNet 6

About The Author

Samson Amaugo

I am Samson Amaugo. I am a full-stack developer and I specialize in DotNet and the MERN stack.

Leave a Reply

Cancel reply

Search Site

Recent Posts

  • Running Entity Framework Migrations in an Aspire-Bootstrapped Orleans Project
  • Using XDebug in Laravel Sail (VSCODE)
  • Custom Redis Streams Provider for Orleans
  • Creating a Custom File Storage Provider for Microsoft Orleans
  • Incremental Generators In C#

Categories

  • EDUCATION
  • Motivation
  • Programming
  • Uncategorized

Get more stuff

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

we respect your privacy and take protecting it seriously

RSS Swacblooms

  • Running Entity Framework Migrations in an Aspire-Bootstrapped Orleans Project
  • Using XDebug in Laravel Sail (VSCODE)
  • Custom Redis Streams Provider for Orleans
  • Creating a Custom File Storage Provider for Microsoft Orleans
  • Incremental Generators In C#
  • Hot Chocolate Data Loader: A Quick Guide
  • Exploring Policy-Based Authorization in Minimal API with .NET 8
  • Using Cloud Firestore in Blazor WebAssembly
  • Serving A VueJs App from DotNet
  • Dynamic Subscriptions in Hot Chocolate 🔥🍫

Swacblooms🦋

Making the Moves
Copyright © 2025 Swacblooms🦋
Swacblooms - Making the Moves