Mega Code Archive

 
Categories / VB.Net / Development
 

Convert ToUInt16 (String) converts string to 16-bit unsigned integer

Class Sample     Public Shared Sub Main()         Dim values() As String = {"1123", "1,123", "one", "1.6e03", "1.2e-02"}         Dim result As UShort         For Each value As String 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 FormatException                 Console.WriteLine("FormatException")             Catch e As OverflowException                 Console.WriteLine("{0} causes OverflowException.", value)             End Try         Next     End Sub End Class