How to use sort and reverse methods in C#


Introduction:
 In this articals we will see how to use sort and reverse method in C#.Display array items in an array and then reverses the elements of the array.another array having string element is used to sort the array elements alphabetically and then display the reverse data.
Example:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ArraySort_ReverseExample

{

    class Program

    {

        public static void ArrDisplay(string[] arr1)

        {

            foreach (string str in arr1)

            {

                Console.WriteLine("value:{0}", str);

 

            }

            Console.WriteLine("\n");

        }

 

              static void Main(string[]args)

            {

                String []arr2=

                {

                    "Rohit","Rahul","Mohit","Gurpreet","Harpreet"

                };

 

                ArrDisplay(arr2);

                Array.Reverse(arr2);

                Console.WriteLine("Here array is reversed.");

                ArrDisplay(arr2);

                string[] arr3 =

                {

                    "This", "is", "an", "example",

                    "of", "an", "array", "and", "how", "to", "sort", "it", "alphabetically"

                };

            ArrDisplay(arr3);

            Console.WriteLine("now array is sorted alphabetically.");

            Array.Sort(arr3);

            ArrDisplay(arr3);

        }

        }

}
Output of the program:
rohit.gif

Thank U. if U have any Suggestions and Comments about my blog, Plz let me know.