using System; public class Test { public static void TestForNumber(String mystring) { Console.WriteLine("Testing {0}:", mystring); Int32 nVal; if (Int32.TryParse(mystring, out nVal)) { Console.WriteLine("\tIt's an integer! ({0})", nVal); } Double dVal; if (Double.TryParse(mystring, out dVal)) { Console.WriteLine("\tIt's a decimal! ({0:0.00})", dVal); } } public static void Main() { String[] tests = new[]{ "foo", "123", "1.23", "$1.23", "1,234", "1,234.56" }; foreach (String test in tests) { TestForNumber(test); } } }