June 17, 2020

Reverse a String in C#

Write a program in c# to reverse a String.
Write a program in c# to reverse a String.

Sample Solution

C# Sharp Code
using System;
using System.Collections.Generic;
namespace AccessSpecifiers
{
    class Program
    {
        static void Main(string[] args)
        {
            string name, stringreverse = "";
            int Lenth;
            Console.Write("Enter string :- ");
            name = Console.ReadLine();
            Lenth = name.Length - 1;
            while (Lenth >= 0)
            {
                stringreverse = stringreverse + name[Lenth];
                Lenth--;

            }
            Console.WriteLine("Revesse string is:  " + stringreverse);

            Console.ReadLine();
        }
    }
}

Sample Output
Write a program in c# to reverse a String.







No comments:

Post a Comment