static void Main(string[] args)
{
Console.WriteLine("请输入要录入的学生个数:");
int i = int.Parse(Console.ReadLine());
Students[] a = new Students[i];
for (int b = 0; b < i; b++)
{
a[b] = new Students();-------这里,他提示我0参数,实际上我也没想在这里有参数啊!
Console.WriteLine("请输入名字:");
a[b].Name = Console.ReadLine();
Console.WriteLine("请输入性别:");
a[b].Sex = Console.ReadLine();
Console.WriteLine("请输入成绩:");
a[b].Cj = int.Parse(Console.ReadLine());
}
Console.WriteLine("1:按成绩升序排列。2:按成绩降序排列。/n 请选择:");
int l = int.Parse(Console.ReadLine());
Students.Px(i, a, l);
}
}
下面是类里面的内容:
class Students
{
private string name;
private string sex;
private int cj;
public string Name
{
set { name = value; }
get { return name; }
}
public string Sex
{
set { sex = value; }
get { return sex; }
}
public int Cj
{
set { cj = value; }
get { return cj; }
}
public Students(string name, string sex, int cj)
{
this.Name = name;
this.Sex= sex;
this.Cj = cj;
}
public static void Px(int p, Students[] a,int l)
{
string n, s;
int cjh;
if (l == 1)
{
for (int b = 0; b <= p; b++)
{
if (a[b].cj < a[b + 1].cj)
{
n = a[b].name;
a[b].name = a[b + 1].name;
a[b + 1].name = n;
s = a[b].sex;
a[b].sex = a[b + 1].sex;
a[b + 1].sex = s;
cjh = a[b].cj;
a[b].cj = a[b + 1].cj;
a[b + 1].cj = cjh;
}
}
Console.WriteLine(a);
}
}