Reverse
Reverses a string.
- Use
string.ToCharArray()to convert the string to an array ofchar,Array.Reverse()to reverse the array. - Use
IEnumerable.ToArray()to create an array ofcharand pass it to anew string().
using System.Linq;
public static partial class _30s
{
public static void Reverse(string s)
{
return new string(s.ToCharArray().Reverse().ToArray());
}
}string s = "Hello World";
_30s.Reverse(s); // "dlroW olleH"