Reversing a string using for loop in C#

In this article i will explain how we can reverse a string using for loop in C#.
  • 15847

Introduction

Many ways or parameters are used to reverse a string in c# such as ref parameter. For loop is a another way by using it we can reverse a string, here is an example below.

Example

using System;

using System.Collections.Generic;

using System.Text;

using System.Reflection;

namespace Dotnetheaven

{

    class Program

    {

        static void Main()

        {

            string name, Revname = "";

            Console.Write("Entert Your Name : ");

            name = Console.ReadLine();

            for (int i = name.Length - 1; i >= 0; i--)

            {

                Revname = Revname + name[i];

            }

            Console.WriteLine("Reverse  String  Is  {0}", Revname);

            Console.ReadLine();

        }

    }

}

 

 The output of the following program

 Clipboard202.jpg

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.