using System;
using System.Globalization;
public class Example
{
public static void Main()
{
NumberFormatInfo provider = new NumberFormatInfo();
provider.PositiveSign = "pos ";
provider.NegativeSign = "neg ";
string[] values= { "pos 34567", "neg 34567"};
foreach (string value in values)
{
try {
Console.WriteLine("{0,17}", Convert.ToUInt16(value, provider));
}
catch (FormatException e) {
Console.WriteLine("{0,17}", e.GetType().Name);
}
}
}
}
|