How to Reverse a Word using C#

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.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application for c#. ps1

Step 2

Do the form just like shown below. ps2

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.
  1.    
  2.         private void reverse_string(string givenString)
  3.         {
  4.             string reverseString = "";
  5.             int lnt = 0;
  6.              
  7.            
  8.             //Get the length of the given string
  9.             lnt = givenString.Length - 1;
  10.             while (lnt >= 0)
  11.             {
  12.                 reverseString = reverseString + givenString[lnt];
  13.                 lnt--;
  14.             }
  15.             //Displaying the reverse word in the listbox
  16.             listBox1.Items.Clear();
  17.             listBox1.Items.Add("Reverse word is : " + reverseString);
  18.         }

Step 4

Call the method that you have created to execute when the button is clicked.
  1.    
  2.         private void button1_Click(object sender, EventArgs e)
  3.         {
  4.             reverse_string(textBox1.Text);
  5.         }
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.

Add new comment