How to Reverse a Word using C#
Submitted by janobe on Tuesday, May 28, 2019 - 18:54.
This time, I will teach you how to reverse a word using C#. This kind of method is a little bit fun most especially if you are a beginner and is trying to explore fun things about coding. In here, when you type any word that you like inside the textbox it will automatically reverse the word once you click the reverse button.
The complete sourcecode is included. You can download it and run it on your computer
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below.
Creating Application
Step 1
Open Microsoft Visual Studio 2015 and create a new windows form application for c#.Step 2
Do the form just like shown below.Step 3
Press F7 to open the code editor. In the code editor, create a method to reverse a given strings that would be displayed in the listbox.- private void reverse_string(string givenString)
- {
- string reverseString = "";
- int lnt = 0;
- //Get the length of the given string
- lnt = givenString.Length - 1;
- while (lnt >= 0)
- {
- reverseString = reverseString + givenString[lnt];
- lnt--;
- }
- //Displaying the reverse word in the listbox
- listBox1.Items.Clear();
- listBox1.Items.Add("Reverse word is : " + reverseString);
- }
Step 4
Call the method that you have created to execute when the button is clicked.- private void button1_Click(object sender, EventArgs e)
- {
- reverse_string(textBox1.Text);
- }
Add new comment
- 403 views