throw if null c# code example
Example 1: trhow exception if is null c#
var firstName = name ?? throw new ArgumentException("Mandatory parameter", nameof(name),);
Example 2: trhow exception if is null c#
public Exception GetException(object instance)
{
return (instance == null) ? new ArgumentNullException() : new ArgumentException();
}
public void Main()
{
object something = null;
throw GetException(something);
}