StringValidatorAttribute.MaxLength 属性

定义

获取或设置分配给属性的字符串允许的最大长度。

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

属性值

一个整数,指示分配给属性的字符串允许的最大长度。

例外

示例

下面的示例演示如何使用 MaxLength 属性。

[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

适用于