C# 小白用两个文本框1和2,文本框1输入整数,点击按钮1文本框2升序输入整数,点击按钮2文本框2降序输入整数。我这样写是哪错了??
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MaoPaoPaiXu
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = "";
String[] str = textBox1.Text.Trim().Split(' ');
int[] a = new int[str.Length];
int temp;
for (int i = 0; i < str.Length; i++)
{
a = int.Parse(str);
}
for (int i = 0; i < a.Length; i++) {
for (int j = 0; j < a.Length; j++) {
if (a[j] > a[j + 1]) {
temp = a[j];
a[j] = a[j + 1];
a[j] = temp;
}
}
textBox2.Text += a + " ";
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox2.Text = "";
String[] str = textBox1.Text.Trim().Split(' ');
int[] a = new int[str.Length];
int temp;
for (int i = 0; i < str.Length; i++)
{
a = int.Parse(str);
}
for (int i = 0; i < a.Length; i++)
{
for (int j = 0; j < a.Length; j++)
{
if (a[j] <a[j + 1])
{
temp = a[j+1];
a[j+1] = a[j ];
a[j] = temp;
}
}
textBox2.Text += a + " ";
}
}
}
}
|