UInt16.MaxValue Bidang

Definisi

Mewakili nilai terbesar yang mungkin dari UInt16. Bidang ini konstan.

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

Nilai Bidang

Value = 65535

Contoh

Contoh berikut menggunakan UInt16.MaxValue properti dan UInt16.MinValue untuk memastikan bahwa Int32 nilai berada dalam rentang UInt16 jenis sebelum mengonversinya menjadi UInt16 nilai. Ini mencegah operasi konversi melemparkan OverflowException jika nilai bilangan UInt16 bulat tidak berada dalam rentang jenis.

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

Keterangan

Nilai konstanta ini adalah 65535; yaitu, 0xFFFF heksadesimal.

Berlaku untuk

Lihat juga