public void Foo(int x) { Contract.Requires(x > 0, "x must be positive"); //Rest of the code }
public void AddPerson(Person p) { Contract.RequiresIn this example, we are using Contract.Requires to specify that the argument 'p' cannot be null. If it is, the caller will receive an ArgumentNullException with the message "p cannot be null". Package/library: The Contract class is part of the System.Diagnostics.Contracts namespace, which is part of the .NET Framework Class Library.(p != null, "p cannot be null"); //Rest of the code }