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;
}
}
}
Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
ReplyDeleteDot Net Training Institute in Chennai
Selenium Testing Training in Chennai | Selenium Coaching Institute in Chennai
Software Testing Course in Chennai | Testing Courses in Chennai
Java Training Institute in Chennai | Core Java Training in Chennai | Java Course and Certification
PHP Course in Chennai
Thanks for giving great kind of information. So useful and practical for me. Thanks for your excellent blog, nice work keep it up thanks for sharing the knowledge.
ReplyDeleteAWS Training in Chennai | AWS Training Institute in Chennai