catch (Exception e)//(ArgumentException e)

来源:互联网 发布:淘宝网购物女装夏装2015款 编辑:程序博客网 时间:2024/05/16 10:35
using System;using System.Collections.Generic;using System.Text;namespace ReverStrApp{    class Program    {        private static string Reverse2(string original)        {            char[] arr = original.ToCharArray();            Array.Reverse(arr);            return new string(arr);        }          public static string Reverse(string str)        {            if (string.IsNullOrEmpty(str))            {                throw new ArgumentException("参数不合法");            }            char[] chars = str.ToCharArray();            int begin = 0;            int end = chars.Length - 1;            char tempChar;            while (begin < end)            {                tempChar = chars[begin];                chars[begin] = chars[end];                chars[end] = tempChar;                begin++;                end--;            }            string strResult = new string(chars);            return strResult;        }            static void Main(string[] args)        {            string s = "abcdef";            string res = Reverse(s);            Console.WriteLine(res);            res = Reverse(res);            Console.WriteLine(res);            try            {                s = Reverse("");            }            catch (Exception e)//(ArgumentException e)            {                Console.WriteLine(e.ToString());            }        }    }}/*fedcbaabcdefSystem.ArgumentException: 参数不合法   在 ReverStrApp.Program.Reverse(String str) 位置 E:\learn\program\CSharp\ReverStrApp\ReverStrApp\Program.cs:行号 24   在 ReverStrApp.Program.Main(String[] args) 位置 E:\learn\program\CSharp\ReverStrApp\ReverStrApp\Program.cs:行号 54请按任意键继续. . . * fedcbaabcdefSystem.ArgumentException: 参数不合法   在 ReverStrApp.Program.Reverse(String str) 位置 E:\learn\program\CSharp\ReverStrApp\ReverStrApp\Program.cs:行号 24   在 ReverStrApp.Program.Main(String[] args) 位置 E:\learn\program\CSharp\ReverStrApp\ReverStrApp\Program.cs:行号 54请按任意键继续. . .  */