Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

UInt16.MaxValue Field

Definition

Namespace:
System
Assemblies:
mscorlib.dll, System.Runtime.dll
Assemblies:
netstandard.dll, System.Runtime.dll
Assembly:
System.Runtime.dll
Assembly:
mscorlib.dll
Assembly:
netstandard.dll
Source:
UInt16.cs
Source:
UInt16.cs
Source:
UInt16.cs
Source:
UInt16.cs
Source:
UInt16.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Represents the largest possible value of UInt16. This field is constant.

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

Field Value

Value = 65535

Examples

The following example uses the UInt16.MaxValue and UInt16.MinValue properties to ensure that an Int32 value is in the range of the UInt16 type before converting it to a UInt16 value. This prevents the conversion operation from throwing an OverflowException if the integer value is not in the range of the UInt16 type.

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

Remarks

The value of this constant is 65535; that is, hexadecimal 0xFFFF.

Applies to

See also


Feedback

Was this page helpful?