Skip to content

Instantly share code, notes, and snippets.

@Edkorenkov
Created June 23, 2022 09:27
Show Gist options
  • Save Edkorenkov/fa8aec0777dcdc6dd4a0c1956ca59af8 to your computer and use it in GitHub Desktop.
Save Edkorenkov/fa8aec0777dcdc6dd4a0c1956ca59af8 to your computer and use it in GitHub Desktop.
Throw Argument Null Exception
// 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