.NET 7 to include new ThrowIfNullOrEmpty ArgumentException guard clause

In .NET 6 Microsoft introduced the ArgumentException.ThrowIfNull guard clause and in .NET 7 (Preview 4) they have introduced ArgumentException.ThrowIfNullOrEmpty.

Using these kind of guard clauses instead of if statement checks results in cleaner code. Here is a example (from Steven Giesel on LinkedIn) with the new guard clause…

I really like it, hopefully Microsoft can continue to add more guard clauses in future .NET releases.

Thanks to¬†Steven Giesel for the heads up about this 👍🏻

Leave a Reply

Your email address will not be published. Required fields are marked *