一个简单的C#倒转字符串程序

来源:互联网 发布:51单片机 自学笔记pdf 编辑:程序博客网 时间:2024/06/05 04:49

   前几天,在网上看了一个很好,很简洁的C#倒转字符串的例子,很好,很方便,就记下来了.兴许以后面试用的上,呵呵.

using System;
using System.Collections.Generic;
using System.Text;

 

namespace ReverseString
{
    public class Program
    {
        static void Main(string[] args)
        {
            string str;
            Console.WriteLine("Please input some string:");
            str = Console.ReadLine();
            str = ReversString(str);
            Console.WriteLine("Now the string of your input is: {0}", str);
            Console.ReadLine();
        }

        private static string ReversString(string str)
        {
            char[] arr = str.ToCharArray();
            Array.Reverse(arr);
            str = new string(arr);
            return str;
        }

    }
}

  

原创粉丝点击