Mega Code Archive

 
Categories / VB.Net / Development
 

Convert ToChar (Object) converts object to a Unicode character

Class Sample    Public Shared Sub Main()         Dim values() As Object = { "r"c, "s", CByte(83), 77,2010, #3/10/2009#, Nothing }         Dim result As Char                  For Each value As Object In values            Try               result = Convert.ToChar(value)               Console.WriteLine("The {0} value {1} converts to {2}.", _                                  value.GetType().Name, value, result)            Catch e As FormatException               Console.WriteLine(e.Message)            Catch e As InvalidCastException               Console.WriteLine("InvalidCastException")            Catch e As OverflowException               Console.WriteLine("OverflowException")            Catch e As NullReferenceException               Console.WriteLine("NullReferenceException")            End Try         Next     End Sub End Class