- Open Visual Studio from Start - - All programs -- Microsoft Visual Studio.
- Then go to to "File" -> "New" -> "Project..." then select Visual C# -> Windows -> Console application.
- After that specify the name such as ReverseString or whatever name you wish and the location of the project and click on the OK button. The new project is created.
I will explain in this article how to reverse a given string in a Windows console application using C# without using a function. This type of question might be asked by an interviewer in a .Net position related interview.
In the above program I have clearly explained in comments which statement is used for which purpose. Now run the program with the input string vithal wadje; the output will be as follows:
My intent for this article is to explain how to answer a question that is often asked in an interview, which is: Write a program to reverse the given String without using the string function. A candidate new to the interview can become totally confused because the first problem is the candidate just thinks about functions, not other techniques to reverse a string.
So considering the preceding requirement and numerous emails sent to me from beginners I have decided to write this article with the basics and specially focusing on the beginner, student and whoever might face this type of question in an interview.
So let us start with the basics.
What is a String ?
A String is a sequence of characters enclosed within double quotation marks.
"vithal wadje" , "C#" , "Mumbai" "Five hundred" etc.
I hope you understand about strings now.
What reversing String Means ?
To change the position of charters from right to left one by one is called reversing a string.
Suppose I have the given input as:
Then the given string can be reversed into:
Now that we completely understand what is meant by reversing a string, next I will explain how to do it step-by-step, as in the following:
From the all examples above I have explained how to reverse the string. I hope this article is useful for beginners and anyone preparing for an interview. If you have any suggestions and feedback please contact me.