Programs to reverse a given string

Problem Defination :- We have a given string and we need to reverse this string using the C# program.
Let's start writting the program on it. I have created a Class named it PracticeExamples and inside this class I have written a void Method ProgramOnReverseString which is taking one parameter as a string , that we need to reverse. Define a integer variable and store the length of givenString using "String.Length".
Now use a for Loop and initialize it from 0 to length of string and print the characters on screen using console.write method of C# as shown in below code.

                
 public class PracticeExamples
    {
        public void ProgramOnReverseString(string givenString)
        {
            int LengthOfString=givenString.Length;
            for(int i=0;i< LengthOfString; i++)
            {
                Console.Write(givenString[LengthOfString - i-1]);
            }
        }
    }           
                

Graphical Representation for Program flow

Image is not available

Now create an instance/object of PracticeExamples class and using this Object call the ProgramOnReverseString method. In method I have passed a string "Sudheer Singh Chouhan" hardcoded , you can input it from keyboard also. Run the application you can get the reverse of the string in output console as shown in the below image.


  internal class Program
    {
        static void Main(string[] args)
        {
            PracticeExamples practiceExamples = new PracticeExamples();
            practiceExamples.ProgramOnReverseString("Sudheer Singh Chouhan");
            Console.ReadKey();
        }
    }          
Image is not available

Image is not available

About the Author
Sudheer Singh Chouhan is a Software Engineer having Expertise in Development Design and Architecting the applications , Project Management , Designing Large Scale Databases in SQL Server since last 17 Years.
Skill Sets :- Microsoft .NET technologies like ASP.Net Core, Web API, LINQ, Web Forms, WinForms, SQL Server, EntityFramework, Design Patterns, Solid Principles, Microservices, AWS Cloud.