RangeAttribute 建構函式

定義

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

多載

名稱 Description
RangeAttribute(Double, Double)

透過使用指定的最小值與最大值初始化類別的新實例 RangeAttribute

RangeAttribute(Int32, Int32)

透過使用指定的最小值與最大值初始化類別的新實例 RangeAttribute

RangeAttribute(Type, String, String)

透過使用指定的最小值、最大值及特定型別,初始化該類別的新 RangeAttribute 實例。

RangeAttribute(Double, Double)

透過使用指定的最小值與最大值初始化類別的新實例 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

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 實例。

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

適用於