This is the simple C# program to reverse the order of words in a given string,
using System;
using System.Text;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Program.ReverseWordOrder("Hello World");
}
static void ReverseWordOrder(string str)
{
int i;
StringBuilder reverseWord = new StringBuilder();
int Start = str.Length - 1;
int End = str.Length - 1;
while (Start > 0)
{
if (str[Start] == ' ')
{
i = Start + 1;
while (i <= End)
{
reverseWord.Append(str[i]);
i++;
}
reverseWord.Append(' ');
End = Start - 1;
}
Start--;
}
for (i = 0; i <= End; i++)
{
reverseWord.Append(str[i]);
}
Console.WriteLine(reverseWord.ToString());
}
}
}
Output: World Hello
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
This is the simple C# program to reverse the order of words in a given string,