Reversing Set of Numbers in C#

In this tutorial, I will teach you how to reverse a set of numbers using C#. This procedure illustrates how to reverse any given numbers in a textbox and it will display in the listbox. Hope this simple program will help to solve your current problem. Follow the step by step guide to see how it works.

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 number.
  1.    
  2.         private void reverse_numbers(int given_numbers)
  3.         {
  4.             int straight_numbers, reverse_number;
  5.             reverse_number = 0;
  6.             try
  7.             {
  8.                 straight_numbers = given_numbers;
  9.  
  10.  
  11.                 while (straight_numbers > 0)
  12.                 {
  13.                     int remainder = straight_numbers % 10;
  14.                     reverse_number = (reverse_number * 10) + remainder;
  15.                     straight_numbers = straight_numbers / 10;
  16.                 }
  17.  
  18.                 listBox1.Items.Clear();
  19.                 listBox1.Items.Add(reverse_number);
  20.             }
  21.             catch (Exception ex)
  22.             {
  23.                 MessageBox.Show(ex.Message);
  24.             }
  25.         }

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_numbers(int.Parse(textBox1.Text));
  5.         }
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