public void DoSomething(string input) { if (input == null) throw new ArgumentNullException(nameof(input)); // Do something with the input }
public void DoSomethingElse(string input1, string input2) { Throw.IfArgumentNull(input1, nameof(input1)); Throw.IfArgumentNull(input2, nameof(input2)); // Do something with the inputs }In Example 2, the Throw.IfArgumentNull method is used to throw an ArgumentNullException with the parameter name as the message for each argument that is null. This helps to ensure that both input1 and input2 are not null before proceeding with the rest of the method. This method belongs to the Microsoft.VisualStudio.Threading package library.