Redigera

Dela via


RangeAttribute Constructors

Definition

Initializes a new instance of the RangeAttribute class.

Overloads

RangeAttribute(Double, Double)

Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.

RangeAttribute(Int32, Int32)

Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.

RangeAttribute(Type, String, String)

Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values and the specific type.

RangeAttribute(Double, Double)

Source:
RangeAttribute.cs
Source:
RangeAttribute.cs
Source:
RangeAttribute.cs

Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.

public:
 RangeAttribute(double minimum, double maximum);
public RangeAttribute (double minimum, double maximum);
new System.ComponentModel.DataAnnotations.RangeAttribute : double * double -> System.ComponentModel.DataAnnotations.RangeAttribute
Public Sub New (minimum As Double, maximum As Double)

Parameters

minimum
Double

Specifies the minimum value allowed for the data field value.

maximum
Double

Specifies the maximum value allowed for the data field value.

Applies to

RangeAttribute(Int32, Int32)

Source:
RangeAttribute.cs
Source:
RangeAttribute.cs
Source:
RangeAttribute.cs

Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.

public:
 RangeAttribute(int minimum, int maximum);
public RangeAttribute (int minimum, int maximum);
new System.ComponentModel.DataAnnotations.RangeAttribute : int * int -> System.ComponentModel.DataAnnotations.RangeAttribute
Public Sub New (minimum As Integer, maximum As Integer)

Parameters

minimum
Int32

Specifies the minimum value allowed for the data field value.

maximum
Int32

Specifies the maximum value allowed for the data field value.

Examples

The following example shows how to use the RangeAttribute to specify the range for an integer data field.

[Range(300, 3000)]
public object ListPrice;
<Range(300, 3000)> _
Public ListPrice As Object

Applies to

RangeAttribute(Type, String, String)

Source:
RangeAttribute.cs
Source:
RangeAttribute.cs
Source:
RangeAttribute.cs

Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values and the specific type.

public:
 RangeAttribute(Type ^ type, System::String ^ minimum, System::String ^ maximum);
public RangeAttribute (Type type, string minimum, string maximum);
new System.ComponentModel.DataAnnotations.RangeAttribute : Type * string * string -> System.ComponentModel.DataAnnotations.RangeAttribute
Public Sub New (type As Type, minimum As String, maximum As String)

Parameters

type
Type

Specifies the type of the object to test.

minimum
String

Specifies the minimum value allowed for the data field value.

maximum
String

Specifies the maximum value allowed for the data field value.

Exceptions

type is null.

Examples

The following example shows how to use the RangeAttribute method to specify the range for a DateTime field. It also includes a custom error message that shows how to use the formatting capabilities of the FormatErrorMessage method.

[Range(typeof(DateTime), "1/2/2004", "3/4/2004",
    ErrorMessage = "Value for {0} must be between {1} and {2}")]
public object SellEndDate;
<Range(GetType(DateTime), "1/2/2004", "3/4/2004", _
       ErrorMessage:="Value for {0} must be between {1} and {2}")> _
Public SellEndDate As Object

Remarks

The object to validate must implement the IComparable interface.

Applies to