将字符串中的字符反转输出

实现效果:

关键知识:(使用了Array类的Reveres静态方法)

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != string.Empty)
            {
                char[] cha = textBox1.Text.ToCharArray();//定义char数组
                Array.Reverse(cha,0,cha.Length);
                textBox2.Text =
                   new StringBuilder().Append(cha).ToString();
            }
            else { MessageBox.Show("请输入","提示:");  }
        }

补充:

如果要反转集合中的元素,可以使用集合对象的Reverse方法

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/9900220.html
今日推荐