Created
June 23, 2022 09:27
-
-
Save Edkorenkov/fa8aec0777dcdc6dd4a0c1956ca59af8 to your computer and use it in GitHub Desktop.
Throw Argument Null Exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// before C#10 and .NET6 | |
// | |
public void GetSomething(string id) | |
{ | |
if (id is null) | |
{ | |
throw new ArgumentNullException(nameof(id)); | |
} | |
// ... and here your code to get some data | |
} | |
// how it looks like now | |
// | |
public void GetSomething(string id) | |
{ | |
ArgumentNullException.ThrowIfNull(id); | |
// ... and here your code to get some data | |
} | |
// or using third-party package [ https://github.com/mantinband/throw ] | |
// | |
public void GetSomething(string id) | |
{ | |
id.ThrowIfNull(); | |
// ... and here your code to get some data | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment