What's New in C# 10: Simplify Argument Null Checking Code

added by DotNetKicks
11/22/2021 6:19:22 AM


This is part of a series on the new features introduced with C# 10. Prior to C# 10 you may have had code similar to the following: public static string Join(string a, string b) { if (a is null) { throw new ArgumentNullException(nameof(a)); } if (b is null) { throw new ArgumentNullException(nameof(b)); } return a + b; } If the parameters a or b are null then an ArgumentNullException will be thrown.