Advertisement
Guest User

01. Reverse String

a guest
May 13th, 2015
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class ReverseString
  8. {
  9.     static void Main()
  10.     {
  11.         string input = Console.ReadLine();
  12.  
  13.         ////Using the build-in reverse method
  14.         //char[] inputChars = input.ToCharArray();
  15.         //Array.Reverse(inputChars);
  16.         //Console.WriteLine(new string (inputChars));
  17.  
  18.         //Without using the build-in reverse method
  19.         char[] inputChars = input.ToCharArray();
  20.         StringBuilder sb = new StringBuilder();
  21.         for (int i = input.Length - 1; i >= 0; --i)
  22.         {
  23.             sb.Append(inputChars[i]);
  24.         }
  25.         Console.WriteLine(sb.ToString());
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement