Parameter Null Checking in C# 11

Programming C#

This new feature is based on, as we already know, it is common to use variations of boilerplate code to validate if the method arguments are null, for example:

public static void M(string s)
{
if (s is null)
{
throw new ArgumentNullException(nameof(s));
}
// Body of the method
}

And now we can abbreviate the intention to check null parameters with !! like:

public static void M(string s!!)
{
// Body of the method
}

This could also be used in checking indexer parameters with get and set:

public string this[string key!!] { get { ... } set { ... } }