把全部人按规则个排序,输出到列表,取不同年级和班级的前几个,那个Group忘了,就用循环判断了
应该是
var Result_List = Infos.OrderByDescending(r => r.Result_Total).OrderBy(c => c.Classes_Id).OrderBy(g => g.Grade_Id).ToList().GroupBy(。。。。。什么的)
程序代码:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
namespace Test_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class Info
{
public int Grade_Id; // 年级Id值
public int Classes_Id; // 班级Id值
public string Grade; // 年级名称
public string Classes; // 班级名称
public string Name; // 姓名
public double Result_1; // 成绩1
public double Result_2; // 成绩2
public double Result_Total; // 总成绩
public Info(int g_id, int c_id, string g, string c, string n, double r1, double r2)
{
Grade_Id = g_id;
Classes_Id = c_id;
Grade = g;
Classes = c;
Name = n;
Result_1 = r1;
Result_2 = r2;
Result_Total = r1 + r2;
}
}
public static List<Info> Infos = new List<Info>();
private void button1_Click(object sender, EventArgs e)
{
Infos.Add(new Info(0, 0, "一年级", "一班", "AA", 10.0, 10.0));
Infos.Add(new Info(0, 0, "一年级", "一班", "BB", 9.0, 9.0));
Infos.Add(new Info(0, 0, "一年级", "一班", "CC", 8.0, 8.0));
Infos.Add(new Info(0, 1, "一年级", "二班", "EE", 6.0, 6.0));
Infos.Add(new Info(0, 1, "一年级", "二班", "FF", 5.0, 6.0));
Infos.Add(new Info(0, 1, "一年级", "二班", "DD", 11.0, 11.0));
Infos.Add(new Info(1, 1, "二年级", "二班", "QQ", 5.0, 5.0));
Infos.Add(new Info(1, 1, "二年级", "二班", "PP", 7.0, 7.0));
Infos.Add(new Info(1, 1, "二年级", "二班", "RR", 6.0, 6.0));
Infos.Add(new Info(1, 0, "二年级", "一班", "KK", 10.0, 10.0));
Infos.Add(new Info(1, 0, "二年级", "一班", "MM", 9.0, 9.0));
Infos.Add(new Info(1, 0, "二年级", "一班", "OO", 8.0, 8.0));
// 全部人先按照年级、班级、总分排序
var Result_List = Infos.OrderByDescending(r => r.Result_Total).OrderBy(c => c.Classes_Id).OrderBy(g => g.Grade_Id).ToList();
// 全部排序出来了,按顺序取不同年级和班级的前几个就可以了,写个循环判断就可以了
for (int i = 0; i < Result_List.Count; i++)
{
richTextBox1.AppendText("年级:" + Result_List[i].Grade + " 班级:" + Result_List[i].Classes + " 姓名:" + Result_List[i].Name + " 成绩1:" + Result_List[i].Result_1 + " 成绩2:" + Result_List[i].Result_2 + " 总分:" + Result_List[i].Result_Total + "\r");
}
}
}
}