Convert.ToSByte Method (Char)
.NET Framework 4
Converts the value of the specified Unicode character to the equivalent 8-bit signed integer.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
- Type: System.Char
The Unicode character to convert.
| Exception | Condition |
|---|---|
| OverflowException | value is greater than SByte.MaxValue. |
The following example attempts to convert each element in an array of Char values to a signed byte.
char[] chars = { 'a', 'z', '\u0007', '\u0200', '\u1023' }; foreach (char ch in chars) { try { sbyte result = Convert.ToSByte(ch); Console.WriteLine("{0} is converted to {1}.", ch, result); } catch (OverflowException) { Console.WriteLine("Unable to convert u+{0} to a byte.", Convert.ToInt16(ch).ToString("X4")); } } // The example displays the following output: // a is converted to 97. // z is converted to 122. // is converted to 7. // Unable to convert u+00C8 to a byte. // Unable to convert u+03FF to a byte.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.