using System;
using System.Globalization;
public class StringParsing
{
public static void Main()
{
string numericString;
NumberStyles styles;
numericString = "10677";
styles = NumberStyles.Integer;
CallTryParse(numericString, styles);
}
private static void CallTryParse(string stringToConvert, NumberStyles styles)
{
Console.WriteLine(stringToConvert);
short number;
bool result = Int16.TryParse(stringToConvert, styles,CultureInfo.InvariantCulture, out number);
if (result)
Console.WriteLine(stringToConvert, number);
else
Console.WriteLine("failed.");
}
}
|