异常类型 01.
class Program { static void Main(string[] args) { Console.WriteLine(TextNumberParser.Parse("one")); Console.WriteLine(TextNumberParser.Parse("on2")); Console.ReadKey(); } } public sealed class TextNumberParser { public static int Parse(string text) { string[] digiTexts = {"zero","one", "two","three"}; int result = Array.IndexOf(digiTexts,text.ToLower()); if (result<0) { //在向方法提供的其中一个参数无效时引发的异常 throw new ArgumentException("传递的参数中至少有一个不符合所调用方法的参数"+nameof(text)); } return result; } }