这个问题一直困扰着我
public class student{
string ID;
string name;
float NET;
float JAVA;
float SQL;
public student(string ID, string name, float NET, float JAVA, float SQL)
{
this.ID = ID;
this.name = name;
= NET;
this.JAVA = JAVA;
this.SQL = SQL;
}
public float avg()
{
return (NET + JAVA + SQL) / 3;
}
public void Show()
{
Console.WriteLine("{0},{1},{2},{3},{4}", ID, name, NET, JAVA, SQL);
}
}
class Program
{
static void Main(string[] args)
{
ArrayList ii = new ArrayList();
do
{
Console.WriteLine("请输入你的ID:");
ConsoleKeyInfo tmp;
if ((tmp = Console.ReadKey()).Key == ConsoleKey.Enter)
{
break;
}
string ID1 = tmp.KeyChar + Console.ReadLine();
Console.WriteLine("请输入你的名字:");
string name = Console.ReadLine();
Console.WriteLine("请输入你的NET成绩:");
string ing = Console.ReadLine();
float at = float.Parse(ing);
Console.WriteLine("请输入你的JAVA成绩:");
string JA = Console.ReadLine();
float VA = float.Parse(JA);
Console.WriteLine("请输入你的SQL成绩:");
string SQ = Console.ReadLine();
float ql = float.Parse(SQ);
Console.WriteLine("你的ID是:{0}\n你的名字是:{1}\n你的NET成绩是:{2}\n你的JAVA成绩是:{3}\n你的SQL成绩是:{4}", ID1, name, at, JA, ql);
student ie = new student(ID1, name, at, VA, ql);
Console.WriteLine("平均成绩为:{0}", ie.avg());
ii.Add(ie);
}
while (true);
for (int a = 0; a < ii.Count - 1; a++)
{
for (int b = 0; b < ii.Count - a - 1; b++)
{
if (((student)(ii[b])).avg() > ((student)(ii[b + 1])).avg())
{
student tmp1;
tmp1 = (student)ii[b];
ii[b] = ii[b + 1];
ii[b + 1] = tmp1;
}
foreach (student oj in ii)
{
oj.Show();
}
}
}