Mega Code Archive

 
Categories / C# / Data Types
 

SByte Parse converts string to its 8-bit signed integer

using System; public class MainClass{     public static void Main(){         string[] values = { "-116", "  -3", "+120", "(1111)", "1111", "-130" };                  foreach (string value in values)         {            try {               Console.WriteLine("Converted '{0}' to the SByte value {1}.",                                 value, SByte.Parse(value));            }            catch (FormatException) {               Console.WriteLine("'{0}' cannot be parsed successfully by SByte type.",                                 value);            }                                          catch (OverflowException) {               Console.WriteLine("'{0}' is out of range of the SByte type.",                                 value);            }                                                                                 }     } }