Ep

Ep

How to reverse string without using Reverse() in C# - Programming for Beginners

Reverse string without using any C# function


Recently in one of the interviews I was asked to reverse the string without using Reverse() in .Net. Below is the simple code to demonstrate how to reverse the string with a simple for each loop.

        string strValue = "Interview question for beginner!";
        string reverseValue = string.Empty;
        foreach (char c in strValue)
        {
            reverseValue = c + reverseValue; // concantenate the characters in a reverse mode
        }

        Response.Write(reverseValue);

Output:

c string,without using,reverse(),programming code,learn C#

How to reverse string without using Reverse() in C# - Programming for Beginners Reviewed by Ravi Kumar on 9:23:00 PM Rating: 5

1 comment:

  1. The result is ok.
    But why does it reads strValue variable's value in reverse mode? Does foreach () loop reads a string in reverse direction?

    ReplyDelete

All Rights Reserved by Etechpulse © 2012 - 2017
Powered By Blogger

Contact Form

Name

Email *

Message *

Powered by Blogger.