C# program to reverse an array elements

In this C# program, we will reverse an array without using Array.Revers() Method.

C# program to reverse an array elements Code:

private static void Main(string[] args)
        {
            int[] array = { 7, 6, 4, 5, 2, 1, 3, 8 };

            Console.Write("Initial Array: ");
            for (int i = 0; i < array.Length; i++)
            {
                Console.Write("{0},", array[i]);
            }
                
            //---- Reverse Array
            for (int i = 0; i < array.Length / 2; i++)
            {
                int tmp = array[i];
                array[i] = array[array.Length - i - 1];
                array[array.Length - i - 1] = tmp;
            }

            Console.Write("\nReversed Array: ");
            for (int i = 0; i < array.Length; i++)
            {
                Console.Write("{0},", array[i]);
            }
            Console.ReadLine();
        }

C# program to reverse an array elements Output:

CSharp-program-to-reverse-an-array-elements

 
We are nothing without our users ! You can help us offer even more high quality content. Please share our page !
Best quality Asp .Net Ajax Control Toolkit tutorials.

Give your valuable comments.

Name
Email
Comment
6 + 3 =
 
About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2022 CodingFusion
75 Important SQL Server queries you should know