Objects in this mirror are closer to Microsoft Technologies. DNM objective is to help users on Microsoft technologies by providing Articles, snippets, Interview Questions.

18 July 2012

Reverse string without using any built in function in C#.NET


In many of interviews, interviewers will ask write a program to reverse a string without using any built function. So in this snippet we will see how to reverse a string easily without using any built function or string function.



class StringReverseProgram
      {
          static void Main(string[] args)
          {
              string normalStr = "This is DotNetMirror";
              string reverseStr = string.Empty;
              foreach (char chr in normalStr)
              {
                  reverseStr = chr + reverseStr;
              }
              Console.WriteLine(reverseStr); //Output : rorriMteNtoD si sihT
              Console.ReadKey();
          }
    }

Output:
 rorriMteNtoD si sihT


0 Comments:

Post a Comment