22+ C# Programs to Reverse a String

This post contains a total of 22+ Hand-Picked C# Program examples to Reverse a String, with Source Code. All the Programs are made using C# Programming language.

You can use the source code of these programs for educational use with credits to the original owner.

Related Posts

Click a Code to Copy it.

1. By I Am Nick

Made by I Am Nick. Simple C# Program to reverse a string. Enter your own string in line ‘string text = “Practice Means Perfect’. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoloLearn {
  class Program {
   static void Main(string[] args) {
        // sample text
    string text = "Practice Means Perfect";
    text = String.Join(
               " ", text.Split(' ').Reverse());
      Console.Write(text);
        }
    }
}

2. By Mouadh Ben Abdallah

Made by Mouadh Ben Abdallah. Input string after running the program. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Mouadh
{
    class Program
    {
        static void Main(string[] args)
        {   
            string word ,str="";
            word=Console.ReadLine();
                for (int i =0; i <word.Length; i++)
            {
                str =word[i]+str;
                
            }
            Console.Write(str);
        }
    }
}

3. By Akash Pal

Made by Akash Pal. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            string str ="", reverse ="" ;
            int Length = 0;
            Console.WriteLine("Enter a word");
            str = Console.ReadLine();
            Length = str.Length-1;
            while (Length>=0) {
                reverse = reverse + str[Length];
                Length--;
            }
            Console.WriteLine("This is your Reverse Word : {0}",reverse);
            Console.ReadLine();
            if(str == reverse){
                Console.WriteLine("This is palindrome ");
            }else{
                Console.WriteLine("This is not palindrome ");
            }
        }
    }
}

4. By Armen

Made by Armen. C# Program to reverse a string. ( Source )

//input only one time
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        
        public static void Reverse(out string text)
            {
                text = Console.ReadLine();
                char[] charT = text.ToCharArray();
                string reverse = String.Empty;
                for (int i = charT.Length - 1; i > -1; i--)
                {
                    reverse += charT[i];
                }
                Console.WriteLine(reverse);
            }
            
        static void Main(string[] args)
        {
            string text; 
            Reverse(out text);
        }
        
    }
}

5. By Akash Pal

Made by Akash Pal. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
	class Program
	{
		static void Main(string[] args)
		{
		    string str = Console.ReadLine();
		    var chrArray = str.ToCharArray();
		    Array.Reverse(chrArray);
		    str= new String(chrArray);
		    Console.WriteLine("Reverse word is {0}",str);
		    Console.ReadLine();
			
		}
	}
}

6. By Mateusz Legend

Made by Mateusz Legend. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{

    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            Console.WriteLine(StringReverse.ReverseWords(s));
        }
        static class StringReverse{
        public static string ReverseWords(string word)
        {
            char[] rev = word.ToCharArray();
            Array.Reverse(rev);
            return new string(rev);
        }}
    }
}

7. By WittyBit

Made by WittyBit. String reverse as CharArray. ( Source )

using System;

namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            string text = "Some string, that we want to reverse. Your advertisment might be here :D";
            string reversed = Reverse(text);
            Console.WriteLine("Normal:\n" + text);
            Console.WriteLine("Reversed:\n" + reversed);
        }
        
        static string Reverse(string s)
        {
            char[] resArr = s.ToCharArray();
            int left = 0;
            int right = resArr.Length - 1;
            
            while (right > left)
            {
                char tmp = resArr[left];
                resArr[left] = resArr[right];
                resArr[right] = tmp;
                ++left;
                --right;
            }

            return new string(resArr);
        }
    }
}

8. By Mohammad Zafar

Made by Mohammad Zafar. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            string origin = Console.ReadLine();
            string reverse ="";
             
            for(int i = origin.Length-1; i>=0; i--)
            {
                reverse += origin[i];
            }
             
            Console.WriteLine("Reverse: " + reverse);
        }
    }
}

9. By Valdemar Arslanovic Fuglsang

Made by Valdemar Arslanovic Fuglsang. Reverse a text string in c# with the Stack class. Just enter a string you want to reverse. ( Source )


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
	class Program
	{
		static void Main(string[] args)
		{
		    Stack<char> st = new Stack<char>();

            Console.WriteLine("Pleas enter a string to reverse!");
            
            Console.WriteLine();
            
           string txt = Console.ReadLine();
           
           Console.Write(txt + " =  ");

            foreach (char a in txt)
            {
                st.Push(a);
            }

            foreach (char a in txt)
            {
                Console.Write(st.Pop());
            }
		}
	}
}

10. By Mohanad Alkhaier

Made by Mohanad Alkhaier. ( Source )

using System;

namespace TEST
{
    class Program
    {
        static void Main(string[] args)
        {

            string str = "Welcome";
            string strR = "";
            for (int x = str.Length-1; x>=0; x--)
            {
                strR += str[x];
            }

            Console.WriteLine(strR);

        }
    }
}

11. By Michael

Made by Michael. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;


namespace SoloLearn
{

    static class Extend{
       public static string reverse(this string value){
      return  new string(value.ToCharArray().Reverse().ToArray());
  }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("See your name reverse ed");
           string myname = Console.ReadLine();
            Console.WriteLine(myname.reverse());
        }
    }
}

12. By Piotr

Made by Piotr. Enter your string in line ‘ Console.WriteLine(StringP.Reverse(“mama”)); ‘. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{ 
    class StringP 
    {
        public static string Reverse(string a) 
        { 
            string revr = "";
            for(int i = a.Length-1;i>=0;i--) 
            {
                revr+=a[i];
            } 
            return(revr);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {    
           Console.WriteLine(StringP.Reverse("mama"));
        }
    }
}

13. By Uliana Dzyoba

Made by Uliana Dzyoba. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Type a string: ");
            string str = Console.ReadLine();
            Console.WriteLine(str);
            Console.WriteLine("Reversed string: " + ReverseString(str));           
        }
        
        static string ReverseString (string str)
        {
            char[] arr = str.ToCharArray();
            int i, j;
            for (i = 0, j = arr.Length - 1; i < j; i++, j--)
            {
                char temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
            string reversed = new string(arr);
            return reversed;
       }       
        
    }
}

14. By IcyJake

Made by IcyJake. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace soloLearn
{
	class program
	{
		static void Main(string[] args)
		{
				Console.WriteLine("This was created by IcyJake!\n");
				Console.WriteLine("Please enter a string you wish to reverse: \n");
				
				String input = Console.ReadLine();
				
				Console.WriteLine("Result: " + reverseTestString(input));
		}
		
		static string reverseTestString(String stringToReverse) 
		{
			char[] reverseArray = stringToReverse.ToCharArray();
			
			Array.Reverse(reverseArray);
			
			return new string(reverseArray);
		}
	}
}

15. By Alphanum3ric

Made by Alphanum3ric. Reverse a String using StringBuilder. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
     /*
       Input any word
     */
    class Program
    {
      public static string getReverse(string number)
        {
         StringBuilder reverse = new StringBuilder();

         
           for(int i = number.Length-1; i >=0; i--)
           {
             char[] element = number.ToCharArray();
               reverse.Append(element[i]);
           }
           
           return reverse.ToString();
        
        }
        static void Main(string[] args)
        {
          string s = Console.ReadLine();
          string reverse = getReverse(s);
          Console.WriteLine(reverse);
        }
    }
}

16. By Fernando Pozzetti

Made by Fernando Pozzetti. Simple C# program to reverse a string. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//sorry for the weird indentation, I got used to this for some reason.

namespace SoloLearn
{
	class Program
	{
        static public string reverse(string s)
        {
            
        if (s.Length != 0) // if the string is NOT empty
        
            {
            char[] charArray = s.ToCharArray(); // creates CharArray from string s
            Array.Reverse(charArray); // uses native Array.Reverse method

            return new string(charArray); //returns string
            }
                    
        else //if s is empty
            {
            return s; //returns empty string
            }
            
        }
	    
		static void Main(string[] args) //main
		{
		string reverseme = "This should be reversed"; //created string
			
		Console.WriteLine(reverse(reverseme)); //using the method
		}
	}
}

17. By Felix

Made by Felix. Enter your string in line ‘ string testString = “This is a string. Reverse it immediately” ‘. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/*
C# program that reverses a string
*/

namespace SoloLearn{
    
	class StringReverse {
	    
	    // String is reversed here
	    static string Reverse(string inputString){
	        // Length - 1 not to exceed string bounds
	        int n = inputString.Length - 1;
	        // Use StringBuilder for performance
	        StringBuilder sb = new StringBuilder();
	        for(int i = 0; i <= n; i++){
	            // Access characters of a string like elements of an array
	            sb.Append(inputString[n-i]);
	        }
	        return sb.ToString();
	    }
	    
		static void Main(string[] args){
			
			string testString = "This is a string. Reverse it immediately";
			
			Console.WriteLine(testString);
			Console.Write("\n");
			Console.WriteLine(Reverse(testString));
			
		}
	}
}

18. By George Tsiga

Made by George Tsiga. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            string word = "nraeLoloS";
            StringBuilder sb = new StringBuilder();
            
            char[] wordArr =      word.ToCharArray();
            int size = wordArr.Length-1;
            for(int i =size;i>=0 ;i--){
                sb.Append(wordArr[i].ToString());
            }
            
            Console.WriteLine(sb.ToString());
        }
    }
}

19. By THUNDER

Made by THUNDER. ( Source )



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
        //sample text
            string reverse = Console.ReadLine();
        Console.WriteLine("you entered :{0}",reverse);
        //reversed sample text
        char[]di=reverse.ToCharArray();
        
            Array.Reverse(di);
            
            Console.Write ("your result is :");
            Console.Write(di);
        }
    }
}

20. By Flamur Zejneli

Made by Flamur Zejneli. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace stringReverseTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Eingabe: ");
            string input = Console.ReadLine();
            string output = "";
            for (int i = input.Length - 1; i >= 0; i--)
            {
                output = output + input[i];
            }

            Console.WriteLine(output);
            Console.ReadKey();
        }
    }
}

21. By kolepusac

Made by kolepusac. ( Source )

/*Input string*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static char[] makeArray(string name)
        {
            int n = name.Length;
            char[] niz = new char[n];

            for (int i = n-1, j = 0; i >= 0 && j < n; i--, j++)
            {
                niz[j] = name[i];
            }

                return niz;
        }

        static void Main(string[] args)
        {
            //Console.Write("Input a string: ");
            string x = Convert.ToString(Console.ReadLine());
            int n = x.Length;
            
            Console.Write("Your string: "+x+" .");
            Console.WriteLine();
            Console.Write("Reverse string: ");
            char[] niz = makeArray(x);
            for (int i = 0; i < n; i++)
            {
                if (i != n - 1)
                    Console.Write(niz[i]);
                else
                    Console.Write(niz[i] + " .");
            }

            Console.ReadKey();
        }
    }
}

22. By Theodore E. Mcfjall

Made by Theodore E. Mcfjall. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            char[] array = input.ToCharArray();
            Array.Reverse(array);
            Console.WriteLine(array);
        }
    }
}

23. By Nikolay Ganev

Made by Nikolay Ganev. ( Source )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a string and see it reversed.");
            string text = Console.ReadLine();
            char[] reverse = text.ToCharArray();
            Array.Reverse(reverse);
            string newText = new string(reverse);
            Console.WriteLine("Reversed string: "+newText);
        }
    }
}