UInt16.MaxValue Campo

Definición

Representa el mayor valor posible de UInt16. Este campo es constante.

public: System::UInt16 MaxValue = 65535;
public const ushort MaxValue = 65535;
val mutable MaxValue : uint16
Public Const MaxValue As UShort  = 65535

Valor de campo

Value = 65535

Ejemplos

En el ejemplo siguiente se usan las UInt16.MaxValue propiedades y UInt16.MinValue para asegurarse de que un Int32 valor está en el intervalo del tipo antes de UInt16 convertirlo en un UInt16 valor. Esto impide que la operación de conversión inicie un OverflowException si el valor entero no está en el intervalo del UInt16 tipo.

int integerValue = 1216; 
ushort uIntegerValue;

if (integerValue >= ushort.MinValue & integerValue <= ushort.MaxValue)
{
   uIntegerValue = (ushort) integerValue;
   Console.WriteLine(uIntegerValue);
} 
else
{
   Console.WriteLine("Unable to convert {0} to a UInt16t.", integerValue);
}
open System

let integerValue = 1216

if integerValue >= int UInt16.MinValue && integerValue <= int UInt16.MaxValue then
    let uIntegerValue = uint16 integerValue
    printfn $"{uIntegerValue}"
else
    printfn $"Unable to convert {integerValue} to a UInt16t."
Dim integerValue As Integer = 1216
Dim uIntegerValue As UShort

If integerValue >= UShort.MinValue And integerValue <= UShort.MaxValue Then
   uIntegerValue = CUShort(integerValue) 
   Console.WriteLine(uIntegerValue)
Else
   Console.WriteLine("Unable to convert {0} to a UInt16t.", integerValue)   
End If

Comentarios

El valor de esta constante es 65535; es decir, 0xFFFF hexadecimal.

Se aplica a

Consulte también