Partager via


RangeAttribute Constructor (Type, String, String)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Initializes a new instance of the RangeAttribute class with the specified minimum and maximum values converted to the specified type.

Namespace:  System.ComponentModel.DataAnnotations
Assembly:  System.ComponentModel.DataAnnotations (in System.ComponentModel.DataAnnotations.dll)

Syntax

'Declaration
Public Sub New ( _
    type As Type, _
    minimum As String, _
    maximum As String _
)
public RangeAttribute(
    Type type,
    string minimum,
    string maximum
)

Parameters

Remarks

The RangeAttribute(Type, String, String) constructor enables you to specify minimum and maximum values that are not integer or double values. You provide the type for the minimum and maximum values. The string values you pass for the minimum and maximum parameters are converted to objects of the type you specified in the type parameter. The type must implement the IComparable interface.

Examples

The following example shows how to specify integer range values for one property and decimal range values for another property.

Public Class Product

  <Range(5, 50)> _
  Public Property ReorderLevel As Integer
    'Implement Get and Set logic
  End Property

  <Range(GetType(Decimal), "5", "5000")> _
  Public Property ListPrice As Decimal
    'Implement Get and Set logic
  End Property

End Class
public class Product
{

  [Range(5, 50)]
  public int ReorderLevel { get; set; }

  [Range(typeof(Decimal),"5", "5000")]
  public decimal ListPrice { get; set; }

}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.