UInt16.MaxValue Field


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

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public const ushort MaxValue

Field Value

Type: System.UInt16

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

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("Unable to convert {0} to a UInt16t.", integerValue);

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top