StringValidatorAttribute.MaxLength Propiedad

Definición

Obtiene o establece la longitud máxima permitida para la cadena que se va a asignar a la propiedad.

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

Valor de propiedad

Entero que indica la longitud máxima permitida para la cadena que se va a asignar a la propiedad.

Excepciones

El valor seleccionado es menor que MinLength.

Ejemplos

En el ejemplo siguiente se muestra cómo usar la propiedad 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

Se aplica a