您的位置:首页 > 其它

定义一个静态成员方法,该方法实现字符串反转

2014-11-21 19:02 441 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "c:\\program files\\Maths\\all.dat";
            Console.WriteLine(Reverse(str));
            Console.ReadKey();
        }
        public static string Reverse(string str)
        {
            //方法主体中使用StringBuilder
           //string str1= Array.Reverse(str);
            char[] str1 = str.ToCharArray();
            string str2 = "";
            for (int i = str1.Length-1; i >= 0; i--)
            {
                str2+=str1[i].ToString();
            }

                return str2;
        }

    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐