Mega Code Archive

 
Categories / VB.Net / Development
 

Convert ToUInt16 (Single) converts single-precision floating-point number to 16-bit unsigned integer

Class Sample    Public Shared Sub Main()         Dim values() As Single = { Single.MinValue, -1.38e10, -1023.299, -12.98, Single.MaxValue }         Dim result As UShort                  For Each value As Single 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} causes OverflowException.", value)            End Try            Next                                      End Sub  End Class