在C#中反转字符串数组

在本文中,我将解释如何在数组中反转字符串。

C#示例 反转字符串数组

namespace demo_arraylist

{
    class Program

    {
        static void Main(string[] args)
        {
            //Program that uses Array to Revers String

            Console.WriteLine(StringHelper.RString("WELCOME"));
            Console.WriteLine(StringHelper.RString("computer"));
            Console.ReadKey();
        }

        //This is a method of Reverse string
        static class StringHelper
        {
            ///Receives string and returns the string with its letters reversed.

            public static string RString(string s)
            {
                char[] arr = s.ToCharArray();
                Array.Reverse(arr);

                return new string(arr);
            }
        }
    }

}
日期:2020-04-11 23:03:50 来源:oir作者:oir