Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7219099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:35:09+00:00 2026-05-28T21:35:09+00:00

I was just researching how can I reverse a String. I found a Program

  • 0

I was just researching how can I reverse a String. I found a Program in C# The Complete Reference Book but i was not able to understand it. Plz anyone Explain me how it works

The Program is here:

using System;
class RevStr 
{
    // Display a string backward.
    public void DisplayRev(string str) 
    {
        if(str.Length > 0)
            DisplayRev(str.Substring(1, str.Length-1));
        else
            return;

        Console.Write(str[0]);
    }
}

class RevStrDemo 
{
    static void Main() 
    {
        string s = "this is a test";
        RevStr rsOb = new RevStr();
        Console.WriteLine("Original string: " + s);
        Console.Write("Reversed string: ");
        rsOb.DisplayRev(s);
        Console.WriteLine();
    }
}
  1. How does this program works?
  2. Does the statement rsOb.DisplayRev(s); call DisplayRev(str.Substring(1, str.Length-1)); for every Character in the string?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T21:35:13+00:00Added an answer on May 28, 2026 at 9:35 pm

    What I’d Recommend

    Have you tried myString.Reverse();

    It would be the easiest way to reverse a string in C# (.Net 3.5 and above).

    Response

    As for your example it is using Recursion to display each character by removing the end character (by creating a substring of the original with the first char removed) then calling itself again until there are no characters remaining.

    You will only need to call DisplayRev(s); once because it recursively displays each character within.

    Explanation Attempt

    For example we have the string "hello".

    The first call will recursively call the function with the substring of "hello" which will be "ello"

    Note that the call to the Console.WriteLine hasn’t been made, because the function DisplayRev has been called so we then step in to the recursive call.

    This will keep on occuring until the string is empty (.Length == 0). Then the function will exit and return to the caller, which will be where the string[0] is “o”, the Console.WriteLine code will be hit writing the “o” to the console, this function will then be exited and the caller of that will then hit the Console.WriteLine, which will be the “l”, this will keep returning until the initial call is reached.

    Thus resulting in your initial string, reversed.

    Reference

    There are a number of tutorials around about recursion. Here’s a few (they’ll be better at explaining it than I am):

    Recursion Example 1
    Recursion Example 2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been researching google on what it is, but haven't been able to find
I have just started researching creating mobile apps and from what I understand one
I have been researching this problem for a while now and I just can't
I spent hours researching the problem, and just want to share a solution in
I've been researching this problem for awhile now and I can't seem to come
For the past couple weeks I have been researching everything I possibly can and
Okay I am newer to python and have been researching this problem but I
I've spent some time researching this and still can't figure it out. It seem
I've been researching about adding Arabic localisation into our software. I understand that mirroring
I've been researching for days on the issude but till now I still haven

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.