static class WordTools
/// Receive string of words and return them in the reversed order.
public static string ReverseWords(string sentence)
string words = sentence.Split(' ');
return string.Join(" ", words);
static void Main()
const string s1 = "blue red green";
const string s2 = "c# rust python";
string rev1 = WordTools.ReverseWords(s1);
string rev2 = WordTools.ReverseWords(s2);
green red blue
python rust c#
Solution notes. Many teams prefer simple and straightforward solutions to this sort of problem. Simple methods are easy to maintain, but may have poor performance.
Meanwhile Elaborate and clever methods, with clever syntax or optimizations, often just lead to more bugs.
A summary. We reversed words in a string using a method that is clear and uses few lines of code. It is easy to enhance when your requirements change.