Advertisement
PolinaKoleva

ReverseString

Feb 1st, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //Write a program that reads a string, reverses it and prints the result at the console.
  6. //Example: "sample"  "elpmas".
  7.  
  8. class Problem2ReverseString
  9. {
  10.     static string Reversed(string text)
  11.     {
  12.         StringBuilder build = new StringBuilder();
  13.         for (int i = text.Length - 1; i >= 0; i--)
  14.         {
  15.             build.Append(text[i]);
  16.         }
  17.         return build.ToString();
  18.     }
  19.     static void Main()
  20.     {
  21.         string text = "hello";
  22.         string reversed = Reversed(text);
  23.         Console.WriteLine(reversed);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement