How to reverse a string without using reverse method in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "abcdef", rev = "";

            int length = s.Length - 1;

            while (length >= 0)
            {
                rev = rev + s[length];
                length--;

            }

            Console.WriteLine(rev);
        }
    }
}

/*
run:
   
fedcba
      
*/

 



answered Apr 3, 2017 by avibootz
...