Best way to reverse a string in C# 2.0
Posted
by Guy
on Stack Overflow
See other posts from Stack Overflow
or by Guy
Published on 2008-10-23T00:31:32Z
Indexed on
2010/03/13
20:05 UTC
Read the original article
Hit count: 158
I've just had to write a string reverse function in C# 2.0 (i.e. LINQ not available) and came up with this:
public string Reverse(string text)
{
char[] cArray = text.ToCharArray();
string reverse = String.Empty;
for (int i = cArray.Length - 1; i > -1; i--)
{
reverse += cArray[i];
}
return reverse;
}
Personally I'm not crazy about the function and am convinced that there's a better way to do it. Is there?
© Stack Overflow or respective owner