共用方式為


StringValidatorAttribute.MinLength 屬性

定義

取得或設定將字串指派給屬性時所允許的最小值。

public:
 property int MinLength { int get(); void set(int value); };
public int MinLength { get; set; }
member this.MinLength : int with get, set
Public Property MinLength As Integer

屬性值

整數,表示將字串指派給屬性時所允許的最小長度。

例外狀況

選取的值大於 MaxLength

範例

下列範例將示範如何使用 MinLength 屬性。

[ConfigurationProperty("fileName", DefaultValue = "default.txt",
    IsRequired = true, IsKey = false)]
[StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\",
    MinLength = 1, MaxLength = 60)]
public string FileName
{
    get
    {
        return (string)this["fileName"];
    }
    set
    {
        this["fileName"] = value;
    }
}

<ConfigurationProperty("fileName", _
DefaultValue:="default.txt", _
IsRequired:=True, _
IsKey:=False), _
StringValidator( _
InvalidCharacters:=" ~!@#$%^&*()[]{}/;'""|\", _
MinLength:=1, _
MaxLength:=60)> _
Public Property FileName() As String
    Get
        Return CStr(Me("fileName"))
    End Get
    Set(ByVal value As String)
        Me("fileName") = value
    End Set
End Property

適用於