fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void TestForNumber(String mystring)
  6. {
  7. Console.WriteLine("Testing {0}:", mystring);
  8.  
  9. Int32 nVal;
  10. if (Int32.TryParse(mystring, out nVal))
  11. {
  12. Console.WriteLine("\tIt's an integer! ({0})", nVal);
  13. }
  14.  
  15. Double dVal;
  16. if (Double.TryParse(mystring, out dVal))
  17. {
  18. Console.WriteLine("\tIt's a decimal! ({0:0.00})", dVal);
  19. }
  20. }
  21.  
  22. public static void Main()
  23. {
  24. String[] tests = new[]{ "foo", "123", "1.23", "$1.23", "1,234", "1,234.56" };
  25. foreach (String test in tests)
  26. {
  27. TestForNumber(test);
  28. }
  29. }
  30. }
Success #stdin #stdout 0.03s 37032KB
stdin
Standard input is empty
stdout
Testing foo:
Testing 123:
	It's an integer! (123)
	It's a decimal! (123.00)
Testing 1.23:
	It's a decimal! (1.23)
Testing $1.23:
	It's a decimal! (1.23)
Testing 1,234:
	It's a decimal! (1234.00)
Testing 1,234.56:
	It's a decimal! (1234.56)