// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Text.RegularExpressions; class MainClass { public static bool IsNumber1(string s) { try { int.Parse(s); return true; } catch(FormatException) { return false; } } public static bool IsNumber2(string s) { for(int i = 0; i < s.Length; i++) { if(!Char.IsDigit(s[i])) { return false; } } return true; } public static bool IsNumber3(string s) { return Regex.IsMatch(s, "^[0-9]+$"); } public static void Test(string s) { Console.WriteLine(s + " " + IsNumber1(s) + " " + IsNumber2(s) + " " + IsNumber3(s)); } public static void Main(string[] args) { Test("123"); Test("abc"); Test("123abc"); } }