Category >
CSHARP
|| Published on :
Friday, July 9, 2021 || Views:
1092
||
program in C# Sharp to reverse a string
Here Pawan Kumar will explain how to program in C# Sharp to reverse a string
using System;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
string DummyString = "hello how are you today? from www.sourcecodehub.com";
Console.WriteLine(DummyString);
Console.WriteLine(ReverseString(DummyString));
}
internal static string ReverseString(string str)
{
char[] charArray = str.ToCharArray();
for (int i = 0, j = str.Length - 1; i < j; i++, j--)
{
charArray[i] = str[j];
charArray[j] = str[i];
}
string reversedstring = new string(charArray);
return reversedstring;
}
}
}
Download Source Codes