using System;
using System.Globalization;
public class StringParsing
{
public static void Main()
{
string numericString;
NumberStyles styles;
numericString = "80c1";
CallTryParse(numericString, NumberStyles.HexNumber);
}
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.");
}
}
|