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 -

2 comments:

  1. We can achieve the above using advanced CSharp skills also ...

    strRev = String.Concat(str.Reverse());

    Try it and enjoy it.

    ReplyDelete
  2. Bhavna Tyagi
    this information is very helpful

    ReplyDelete