using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { List<Student> list = new List<Student>(); list.Add(new Student("张三 ", 89)); list.Add(new Student("王五", 85)); list.Add(new Student("李四", 94)); list.Add(new Student("牛二", 73)); list.Add(new Student("朱一", 63)); list.Sort(); dataGridView1.DataSource = list; } } class Student : IComparable<Student> { public int CompareTo(Student stu) { return stu.score.CompareTo(this.score); } public Student() { } public Student(String name, int score) { this.name = name; this.score = score; } private String name; public String Name { get { return name; } set { name = value; } } private int score; public int Score { get { return score; } set { score = value; } } } }
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
List<Student> list = new List<Student>();
list.Add(new Student("张三 ", 89));
list.Add(new Student("王五", 85));
list.Add(new Student("李四", 94));
list.Add(new Student("牛二", 73));
list.Add(new Student("朱一", 63));
list.Sort();
dataGridView1.DataSource = list;
}
}
class Student : IComparable<Student>
{
public int CompareTo(Student stu)
{
return stu.score.CompareTo(this.score);
}
public Student()
{
}
public Student(String name, int score)
{
this.name = name;
this.score = score;
}
private String name; public String Name
{
get { return name; }
set { name = value; }
}
private int score; public int Score
{
get { return score; }
set { score = value; }
}
}
}
+1- -