C# - Reverse String
I have given here C# program to reverse the given string.
Source Code
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static bool ReverseString(string src, ref string dst)
{
dst = "";
for (int i = src.Length - 1; i >= 0; i--)
{
dst += src[i];
}
return true;
}
static void Main(string[] args)
{
Console.Write("Enter a String: ");
string s = Console.ReadLine();
string d = null;
ReverseString(s, ref d);
Console.WriteLine("Given String: " + s);
Console.WriteLine("Reversed String: " + d);
}
}
}
Output
Enter a String: malayalam
Given String: malayalam
Reversed String: malayalam
Press any key to continue . . .
Enter a String: Kathir
Given String: Kathir
Reversed String: rihtaK
Press any key to continue . . .
|