RangeAttribute 建構函式

定義

初始化 RangeAttribute 類別的新執行個體。

多載

RangeAttribute(Double, Double)

使用指定的最大值和最小值,初始化 RangeAttribute 類別的新執行個體。

RangeAttribute(Int32, Int32)

使用指定的最大值和最小值,初始化 RangeAttribute 類別的新執行個體。

RangeAttribute(Type, String, String)

使用指定的最大值、最小值和特定型別,初始化 RangeAttribute 類別的新執行個體。

RangeAttribute(Double, Double)

來源:
RangeAttribute.cs
來源:
RangeAttribute.cs
來源:
RangeAttribute.cs

使用指定的最大值和最小值,初始化 RangeAttribute 類別的新執行個體。

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)

參數

minimum
Double

指定資料欄位值允許的最小值。

maximum
Double

指定資料欄位值允許的最大值。

適用於

RangeAttribute(Int32, Int32)

來源:
RangeAttribute.cs
來源:
RangeAttribute.cs
來源:
RangeAttribute.cs

使用指定的最大值和最小值,初始化 RangeAttribute 類別的新執行個體。

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)

參數

minimum
Int32

指定資料欄位值允許的最小值。

maximum
Int32

指定資料欄位值允許的最大值。

範例

下列範例示範如何使用 RangeAttribute 來指定整數數據欄位的範圍。

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

適用於

RangeAttribute(Type, String, String)

來源:
RangeAttribute.cs
來源:
RangeAttribute.cs
來源:
RangeAttribute.cs

使用指定的最大值、最小值和特定型別,初始化 RangeAttribute 類別的新執行個體。

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)

參數

type
Type

指定要測試的物件型別。

minimum
String

指定資料欄位值允許的最小值。

maximum
String

指定資料欄位值允許的最大值。

例外狀況

typenull

範例

下列範例示範如何使用 RangeAttribute 方法來指定欄位的範圍 DateTime 。 它也包含自定義錯誤訊息,說明如何使用 方法的格式 FormatErrorMessage 設定功能。

[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

備註

要驗證的對象必須實作 IComparable 介面。

適用於