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

속성 값

속성에 할당할 문자열에 허용되는 최대 길이를 나타내는 정수입니다.

예외

선택한 값이 MinLength보다 작은 경우

예제

다음 예제에서는 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

적용 대상