Objects in this mirror are closer to Microsoft Technologies. DNM objective is to help users on Microsoft technologies by providing Articles, snippets, Interview Questions.

31 July 2012

Reverse string using Array.Reverse function in .NET


In this snippet we will a simple program to reverse a string using Array.Reverse function in .NET.
Array.Reverse Method - Reverses the order of the elements in a one-dimensional Array or in a portion of the Array.

Reverse string using Array.Reverse function
   class ReverseString
    {
        static void Main()
        {
            Console.WriteLine(ReverseStr("DotNetMirror"));
            Console.WriteLine(ReverseStr(".NET Mirror"));      
            Console.ReadLine();
        }
        public static string ReverseStr(string s)
        {
            char[] arr = s.ToCharArray();
            Array.Reverse(arr);
            return new string(arr);           
        }

    }

Output:
rorriMteNtoD
rorriM TEN.

0 Comments:

Post a Comment