ArgumentNullExceptions in C# with Just 1 Line of Code!

preview_player
Показать описание
I guarantee this will reduce the lines of code in your codebase! Do CTRL/CMD + F for ArgumentNullException and replace it with the method in this video 🤯

With this you can check and throw, if needed, an ArgumentNullException with just 1 line of code.

💝 Join this channel to get access to perks:

Disclaimer: this channel is done on personal title, in my free time, and not officially affiliated with or endorsed by Microsoft (my employer) in any way. Opinions and views are my own.

🔗 Links

⏱ Timestamps
0:00 - ArgumentNullException.ThrowIfNull()
0:08 - How You're Checking for Null Now
0:23 - Use ArgumentNullException.ThrowIfNull or ThrowIfNullOrEmpty

🙋‍♂️ Also find my...

#csharp #argumentnullexception #exceptionhandling #dotnet
Рекомендации по теме
Комментарии
Автор

Small error in the sample code, the ThrowIfNull method takes 2 parameters. The first is the variable to check for null, the second is the name of the parameter that will end up in the exception if thrown.

So the correct call would be ArgumentNullException.ThrowIfNull(subscriber, nameof(subscriber));

jfversluis
Автор

Hello Gerald, one question: On the second sample NullOrEmpty, does it also validates against whitespaces only on a string? just curiosity. Thanks in advance!!

iVictorHugo
Автор

Hey @Gerald, Is there any fix date for Stable MAUI ?

pratham_dev