Sponsored Ad

Monday, January 17, 2011

How to Reverse an Array using C# Method

C# provide a inbuilt method to reverse the given array in a efficient way. You can use this med and just pass the array into this function by reference and the array will converted in reverse order. The following example will help you to understand the use of array.reverse method.

How to Reverse an Array using C# Method

using System;

namespace MyApp
{
    class ArrayReverse
    {
        static void Main(string[] args)
        {
            string[] strArray = { "ten", "nine", "eight", "seven" };
            Console.WriteLine("Before Reverse: ");
            foreach(string str in strArray)
                Console.Write(str + " ");
            Array.Reverse(strArray);

            Console.WriteLine("");
            Console.WriteLine("After Reverse: ");
            foreach (string str in strArray)
                Console.Write(str + " ");

            Console.ReadLine();
          }         
    }
}

No comments:

Post a Comment

Sponsored Ad

Development Updates