Convert.ToByte Method (Char)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Converts the value of the specified Unicode character to the equivalent 8-bit unsigned integer.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

Public Shared Function ToByte (
	value As Char
) As Byte


Type: System.Char

The Unicode character to convert.

Return Value

Type: System.Byte

An 8-bit unsigned integer that is equivalent to value.

Exception Condition

value represents a number that is greater than Byte.MaxValue.

This method returns an unsigned byte value that represents the numeric code of the Char object passed to it. In the .NET Framework, a Char object is a 16-bit value. This means that the method is suitable for returning the numeric codes of characters in the ASCII character range or in the Unicode C0 Controls and Basic Latin, and C1 Controls and Latin-1 Supplement ranges, from U+0000 to U+00FF.

The following example converts an array of Char values to Byte values.

Dim chars() As Char = { "a"c, "z"c, ChrW(7), ChrW(1023) }
For Each ch As Char in chars
      Dim result As Byte = Convert.ToByte(ch)
      Console.WriteLine("{0} is converted to {1}.", ch, result)
   Catch e As OverflowException
      Console.WriteLIne("Unable to convert u+{0} to a byte.", _
   End Try
' The example displays the following output:
'       a is converted to 97.
'       z is converted to 122.
'        is converted to 7.
'       Unable to convert u+03FF to a byte.      

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top