Reverse String with two different logic using C#
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CalculationApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter String For Reverse.");
string str = Console.ReadLine();
string rev = Calculation.revString1(str);
Console.WriteLine("Orignal String = " + str);
Console.WriteLine("Reversed String1 = " + rev);
string rev1 = Calculation.revString2(str);
Console.WriteLine("Reversed String2 = " + rev1);
Console.ReadLine();
}
}
}
Calculation.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CalculationApp
{
public static class Calculation
{
public static string revString1(string str)
{
char[] charArray = str.ToCharArray();
char[] rev = new char[charArray.Length];
int j = 0;
for (int i = charArray.Length - 1; i >= 0; i--)
{
rev[j++] = charArray[i];
}
return new string(rev);
}
public static string revString2(string Str)
{
int L;
string Revstr = string.Empty;
L = Str.Length - 1;
while (L >= 0)
{
Revstr = Revstr + Str[L];
L--;
}
return Revstr;
}
}
}