using System;
using System.Globalization;
public class Example
{
public static void Main()
{
NumberStyles style;
sbyte number;
string[] values1 = { " 121 ", "121", "-121" };
style = NumberStyles.Integer | NumberStyles.AllowTrailingSign;
string[] values2 = { " 103+", " 103 +", "+103", "(103)", " +103 " };
Console.WriteLine("Styles: {0}", style.ToString());
foreach (string value in values2)
{
try {
number = SByte.Parse(value, style);
Console.WriteLine(" Converted '{0}' to {1}.", value, number);
}
catch (FormatException) {
Console.WriteLine(" Unable to parse '{0}'.", value);
}
catch (OverflowException) {
Console.WriteLine(" '{0}' is out of range of the SByte type.", value);
}
}
}
}