共用方式為


ValidateRange 屬性宣告

ValidateRange 屬性會指定 Cmdlet 參數自變數的最小值和最大值(範圍)。 Windows PowerShell 函式也可以使用此屬性。

語法

[ValidateRange(object minRange, object maxRange)]

參數

MinRangeSystem.Object) 必要。 指定允許的最小值。

MaxRangeSystem.Object) 必要。 指定允許的最大值。

備註

  • MinRange 參數的值大於 MaxRange 參數的值時,Windows PowerShell 運行時間會擲回建構錯誤。

  • Windows PowerShell 運行時間會在下列情況下擲回驗證錯誤:

    • 當自變數的值小於 MinRange 限制或大於 MaxRange 限制時。

    • 當自變數的類型與 MinRangeMaxRange 參數不同時。

  • ValidateRange 屬性是由 System.Management.Automation.ValidateRangeAttribute 類別所定義。

另請參閱

System.Management.Automation.ValidateRangeAttribute

撰寫 Windows PowerShell Cmdlet