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

来源:互联网 发布:apache 2.4 windows 编辑:程序博客网 时间:2024/04/30 08:00
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;        }    }}

0 0
原创粉丝点击