Thursday, May 28, 2009

Reverse String in C#

public class clsTest
{

//Creating function to reverse the String
public string StrRev( string str )
{
char[] charArr = str.ToCharArray();
Array.Reverse( charArr );
return new string( charArr );
}

//Calling the Function

protected void Page_Load(object sender, EventArg e)
{
Response.Write(StrRev("This is a test"));
}

}


//Output
tset a si sihT

No comments:

Post a Comment