Reverse the words Array in C#

In this article I will explain that how to Reverse the words in Array.
  • 3375

Reverse the words in an Array. you want to reverse.  use the 'const' modifier here, which means the strings can't be changed. First sentence is reversed. this method is static because it doesn't save state. Separate words on spaces with Split. Reverse the words with the efficient Array.Reverse method. Join the array on a space.

 

namespace demo_arraylist

{

    class Program

    {

        static void Main(string[] args)

        {

            //Program that uses Array to Revers Word

            const string s1 = "This is Reverse word";   

            string rev1 = Words.RWords(s1);

            Console.WriteLine(rev1);

            Console.ReadKey();

        }

        //This is a method of Reverse

        static class Words

        {

            public static string RWords(string strword)

            {

                string[] words = strword.Split(' ');

                Array.Reverse(words);

                return string.Join(" ", words);

            }

        }

    }

}

Output

reverse word.jpg

Ask Your Question 

Got a programming related question? You may want to post your question here 

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.