设计一个简单的windows程序,输入5个数字,然后排序并输出。

(1)新建Windows应用程序MyApplicaton4,添加控件。
设计一个简单的windows程序,输入5个数字,然后排序并输出。
(2)为按钮的单击事件添加代码:
private void button1_Click(object sender, EventArgs e)
{
string [] number = textBox1.Text.Split(’,’);
int[]temp = new int[number.Length];
int len=number .Length ;
//转换成数字
for (int i =0; i < len; i++)
{
temp[i] = Convert.ToInt32(number[i]);
}
int te;
//从大到小
for (int i = 0; i < len-1; i++) {
for (int j = i+1; j < len; j++) {
if (temp[j] > temp[i])
{
te = temp[j];
temp[j] = temp[i];
temp[i] = te;
}
}
textBox3.Text=textBox3 .Text + temp[i]+",";
}
textBox3.Text = textBox3.Text + temp[len-1];
//从小到大
for (int i = 0; i < len - 1; i++)
{
for (int j = i + 1; j < len; j++)
{
if (temp[j] < temp[i])
{
te = temp[j];
temp[j] = temp[i];
temp[i] = te;
}
}
textBox2.Text =textBox2.Text + temp[i]+",";
}
textBox2.Text = textBox2.Text + temp[len-1];
}

(3)运行结果为:
设计一个简单的windows程序,输入5个数字,然后排序并输出。