Tuesday, October 17, 2006

Reverse String Function


This is a simple reverse string function that uses the StringBuilder class optimizing resources..



public static string ReverseString(string str){

if(str == null str.Length <= 1){
return str;
}

StringBuilder revStr = new StringBuilder(str.Length);

for(int count=str.Length-1; count>-1;count--){
revStr.Append(str[count]);
}

return revStr.ToString();

}

No comments: