UInt16.MaxValue 字段

定义

表示 UInt16 的最大可能值。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

字段值

示例

下面的示例使用 UInt16.MaxValueUInt16.MinValue 属性,以确保 Int32 值在转换为 UInt16 值之前在 UInt16 类型的范围内。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. 如果整数值不在 UInt16 类型的范围内,则这会阻止转换操作引发 OverflowExceptionThis 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);
}     
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   

注解

此常量的值为 65535;即十六进制0xFFFF。The value of this constant is 65535; that is, hexadecimal 0xFFFF.

适用于

另请参阅