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());
            }
        }
    }
}
/*
fedcba
abcdef
System.ArgumentException: 参数不合法
   在 ReverStrApp.Program.Reverse(String str) 位置 E:\learn\program\CSharp\Rever
StrApp\ReverStrApp\Program.cs:行号 24
   在 ReverStrApp.Program.Main(String[] args) 位置 E:\learn\program\CSharp\Rever
StrApp\ReverStrApp\Program.cs:行号 54
请按任意键继续. . .
 * 
fedcba
abcdef
System.ArgumentException: 参数不合法
   在 ReverStrApp.Program.Reverse(String str) 位置 E:\learn\program\CSharp\Rever
StrApp\ReverStrApp\Program.cs:行号 24
   在 ReverStrApp.Program.Main(String[] args) 位置 E:\learn\program\CSharp\Rever
StrApp\ReverStrApp\Program.cs:行号 54
请按任意键继续. . . 
 */