Implement a function to reverse the order of words in a given sentence.
Implement a function to reverse the order of words in a given sentence.
9414-Jun-2023
Home / DeveloperSection / Forums / Implement a function to reverse the order of words in a given sentence.
Aryan Kumar
15-Jun-2023Sure, here is a C# function to reverse the order of words in a given sentence:
C#
This function first splits the sentence into words using the Split() method. It then reverses the order of the words using the Reverse() method. Finally, it joins the words back together into a sentence using the Join() method.
Here is an example of how to use the ReverseWords() function:
C#
This code will print the following output:
Code snippet