反转字符串

    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            Console.WriteLine(ReverseByFun(str));
            Console.WriteLine(ReverseByArray(str));
        }

        /// <summary>
        /// 方法一
        /// </summary>
        /// <param name="str">待反转字符串</param>
        /// <returns></returns>
        private static string ReverseByFun(string str)
        {
            char[] rev = str.ToCharArray();
            Array.Reverse(rev);
            return new string(rev);

            /*//或者以下代码
            string strRev = null;
            for (int i = 0; i < rev.Length; i++)
            {
                strRev += rev[i];
            }
            return strRev;
            */ 
        }

        /// <summary>
        /// 方法二
        /// </summary>
        /// <param name="str">待反转字符串</param>
        /// <returns></returns>
        private static string ReverseByArray(string str)
        {
            char[] rev = str.ToCharArray();
            string strRev = null;
            for (int i = rev.Length - 1; i >= 0; i--)
            {
                strRev += rev[i];
            }
            return strRev;
        }
    }
原文地址:https://www.cnblogs.com/myjacky/p/3316120.html