Skip to content

Instantly share code, notes, and snippets.

@jsonmez
Created May 15, 2014 16:31
Show Gist options
  • Save jsonmez/001f412f4eb1178f1f6e to your computer and use it in GitHub Desktop.
Save jsonmez/001f412f4eb1178f1f6e to your computer and use it in GitHub Desktop.
Age Example
public void ValidateCustomer(int maximumAge)
{
//...
}
ValidateCustomer(25);
// Using an Age class to restrict values
public class Age
{
public Age(int age)
{
if(age < 0 || age > 130)
throw new Exception("Invalid age. Age must be between 0 and 130");
}
}
public void ValidateCustomer(Age maximumAge)
{
// ...
}
var customerAge = new Age(25);
ValidateCustomer(age);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment