C# 从控制台读取数字
try { int number = Convert.ToInt32 (Console.ReadLine()); Console.WriteLine ("Number: " + number); } catch (FormatException e) { Console.WriteLine (e.Message); }
或者
try { int number = Int32.Parse (Console.ReadLine()); Console.WriteLine ("Number: " + number); } catch (ArgumentNullException e) { Console.WriteLine (e.Message); }