using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using Microsoft.VisualBasic;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
ArrayList alist = new ArrayList();
student stu = new student();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "学生信息情况" + "\r\n" + "姓名" + "\t\t" + "学号" + "\t\t" + "英语成绩" + "\t" + "C#成绩" + "\t\t" + "平均成绩" + "\r\n";
for (int j = 0; j < 2; j++)
{
while (true)
{
stu.name = Microsoft.VisualBasic.Interaction.InputBox("请输入名字", "输入名字", "黄辉", -1, -1);
alist.Add(stu.name);
break;
}
while (true)
{
stu.number = Microsoft.VisualBasic.Interaction.InputBox("请输入学号", "输入学号", "1215080131", -1, -1);
alist.Add(stu.number);
break;
}
while(true)
{
stu.score1 = Convert.ToInt32(Microsoft.VisualBasic.Interaction.InputBox("请输入成绩", "输入成绩", "90", -1, -1));
alist.Add(stu.score1);
stu.score2 = Convert.ToInt32(Microsoft.VisualBasic.Interaction.InputBox("请输入成绩", "输入成绩", "90", -1, -1));
alist.Add(stu.score2);
break;
}
stu.Averger = (stu.score1 + stu.score2) / 2;
textBox1.Text = textBox1.Text + stu.name + "\t\t" + stu.number + "\t" + stu.score1.ToString() + "\t\t" + stu.score2 + "\t\t" + stu.Averger + "\r\n";
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox2.Text = "升序排列" + "\r\n" + "学号" + "\t\t" + "姓名" + "\t\t" + "英语成绩" + "\t" + "C#成绩" + "\t\t" + "平均成绩" + "\r\n";
alist.Sort();
foreach (string i in alist)
{
textBox2.Text = textBox2.Text + i + "\t"+"\r\n";
}
}
}
public class student : IComparable
{
public string name;
public string number;
public int score1;
public int score2;
public float Averger = 0;
public student()
{
}
public student(string name, string number, int score1, int score2)
{
this.name = name;
this.number = number;
this.score1 = score1;
this.score2 = score2;
}
public int CompareTo(object num)
{
student otherStudent = num as student;
int result = this.(otherStudent.number);
return result;
}
}
}
还是无法排序诶。。。。呜呜。。。。
帮帮。。。