Mega Code Archive

 
Categories / VB.Net / Development
 

Convert ToUInt16 (Double) converts double-precision floating-point number to 16-bit unsigned integer

Class Sample    Public Shared Sub Main()         Dim values() As Double = { Double.MinValue, 9.1e-16, 1.919, Double.MaxValue }         Dim result As UShort                  For Each value As Double In values            Try               result = Convert.ToUInt16(value)               Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.", _                                 value.GetType().Name, value, _                                 result.GetType().Name, result)            Catch e As OverflowException               Console.WriteLine("{0} is outside the range of the UInt16 type.", value)            End Try            Next                                      End Sub  End Class