UInt16.MaxValue Fält
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Representerar det största möjliga värdet för UInt16. Det här fältet är konstant.
public: System::UInt16 MaxValue = 65535;
public const ushort MaxValue = 65535;
val mutable MaxValue : uint16
Public Const MaxValue As UShort = 65535
Fältvärde
Value = 65535Exempel
I följande exempel används UInt16.MaxValue egenskaperna och UInt16.MinValue för att säkerställa att ett Int32 värde finns i intervallet för UInt16 typen innan det konverteras till ett UInt16 värde. Detta förhindrar att konverteringsåtgärden genererar ett OverflowException om heltalsvärdet inte finns i typens UInt16 intervall.
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
Kommentarer
Värdet för den här konstanten är 65535; hexadecimal 0xFFFF.