Reverse word of full sentence
You would need to split the string into words and the reverse those instead of reversing the characters:
text = String.Join(" ", text.Split(' ').Reverse())
In framework 3.5:
text = String.Join(" ", text.Split(' ').Reverse().ToArray())
In framework 2.0:
string[] words = text.Split(' ');
Array.Reverse(words);
text = String.Join(" ", words);
"please send me the code of this program."
Okay ...
using System;
using System.Linq;
class Program
{
static void Main(string[] args)
{
string text = "My name is Archit Patel";
Console.WriteLine(string.Join(" ", text.Split(' ').Reverse()));
}
}
Now: what have you learned?
Also, as Guffa points out, for versions below .Net 4.0 you'll need to add .ToArray()
since string.Join doesn't have the correct overload in those versions.