Reverse String In ASP.NET C#

Way1: Using Array.Reverse() method

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. namespace ProgrammingInterviewFAQ.ReverseString {  
  7.     class ReverseString {  
  8.         static void Main() {  
  9.             string input = "karthik";  
  10.             char[] c = input.ToCharArray();  
  11.             Array.Reverse(c);  
  12.             string output = new string(c);  
  13.             Console.WriteLine(output);  
  14.             Console.ReadLine();  
  15.         }  
  16.     } //End of Class  
  17. }  
Way2 : without using Array.Reverse() method
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. namespace ProgrammingInterviewFAQ.ReverseString {  
  7.     class ReverseStringWithoutUsingReverseFunction {  
  8.         static void Main(string[] args) {  
  9.                 string input = "Karthik";  
  10.                 string output = string.Empty; //variable to stored the result  
  11.                 int Length = input.Length - 1;  
  12.                 while (Length >= 0) {  
  13.                     output = output + input[Length];  
  14.                     Length--;  
  15.                 } // End of while  
  16.                 Console.WriteLine("Reversed String Is {0}", output);  
  17.                 Console.ReadLine();  
  18.             } // End of main  
  19.     }