public class MyClass { [Range(1, 10)] public int MyProperty { get; set; } }
public class MyMethodClass { public void DoSomething([Range(0,100)]int value) { // do something with value } }In this example, the Range attribute is used to limit the valid range of values for the "value" parameter in the DoSomething method to be between 0 and 100 inclusive. The Range attribute is part of the System.ComponentModel.DataAnnotations namespace and is included in the System.ComponentModel.DataAnnotations.dll library.