How to reverse the order of the words in a string with C#

1 Answer

0 votes
using System;

class Program
{
    static string ReverseWords(string s) {
        string [] arr = s.Split(' ');
 
        Array.Reverse(arr);
        
        return string.Join(" ", arr);
    }
    static void Main() {
            string s = "C# is a general purpose programming language";

            s = ReverseWords(s);
            
            Console.Write(s);
    }
}




/*
run:
           
language programming purpose general a is C#
           
*/

 



answered Sep 4, 2021 by avibootz

Related questions

1 answer 113 views
1 answer 144 views
1 answer 123 views
3 answers 209 views
209 views asked Aug 1, 2021 by avibootz
...