System.Convert.ToUInt16 Method

Converts the value of the specified double-precision floating-point number to an equivalent 16-bit unsigned integer.

Syntax

[System.CLSCompliant(false)]
public static ushort ToUInt16 (double value)

Parameters

value
The double-precision floating-point number to convert.

Returns

value, rounded to the nearest 16-bit unsigned integer. If value is halfway between two whole numbers, the even number is returned; that is, 4.5 is converted to 4, and 5.5 is converted to 6.

Exceptions

TypeReason
OverflowException value is greater than ushort.MaxValue or less than ushort.MinValue.

Remarks

Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6.

This member is not CLS-compliant. For a CLS-compliant alternative, use Convert.ToInt32(object)(double).

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0