Showing posts with label reverse. Show all posts
Showing posts with label reverse. Show all posts

Friday, March 26, 2010

Reverse a String in C#

open a console application project in c# language in your editor and just paste the following code in your class's brackets -

static void Main(string[] args)
{
Console.Write("Enter String: "); String temp = Console.ReadLine();
Console.WriteLine("\n");
int len = temp.Length;
char[] arr = new char[len];

for (int i = 0; i < len; i++)
{ arr[i] = temp[len - 1 - i];
}
Console.WriteLine(arr);
Console.Read();
}

Output is -