public void SampleMethod(string input) { VerifyArgument.IsNotNullOrEmpty(input, nameof(input)); //rest of the code }
public void SampleMethod(int age) { VerifyArgument.IsInRange(age, 18, 60, nameof(age)); //rest of the code }This code will check if the age is between 18 and 60. If it is not within the range, it will throw an ArgumentOutOfRangeException with the parameter name. These examples are from the NuGet package library called Enforce.ArgumentValidation. This package contains the VerifyArgument method along with other validation methods.