In this example,i’ll show you How to reverse a string in C# Form Application.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | private void button1_Click(object sender, EventArgs e) { //this section create a string variable. string characters = textBox1.Text; label1.Text = "string of characters : " + characters + Environment.NewLine; //this line create a char array from string. char[] chars = characters.ToCharArray(); //this line reverse elements of char array. Array.Reverse(chars); //this line convert char array to string. string reversedString = new string(chars); label1.Text += "reversed string : "; label1.Text += reversedString; } |