Write a program to reverse a string?
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string str = "Hello";
char[] revStr = new char[str.Length];
int j = 0;
//Reverse a string
for(int i=str.Length-1;i>=0;i--)
{
revStr[j++] = str[i];
}
Console.WriteLine("Reverse String: {0}", new String(revStr));
}
}
}
No comments:
Post a Comment