public class Student{public string Name {get; set;} public int Age {get; set;} Public Student (String _name, int. _age) {this. Name = _name; This. age = _age; }}public static test1 () {list<student> liststudent = new list<student> (); Student S1 = new Student ("Xiaoming", 20); Student s2 = new Student ("Lifang", 30); Student s3 = new Student ("Liul", 10); Student S4 = new Student ("Amie", 4); Liststudent.add (S1); Liststudent.add (S2); Liststudent.add (S3); Liststudent.add (S4); Method one//construct query to list sort ienumerable<student> sortedstudentlist = from St in liststudent St. Age Descending, St. Name Ascending Select St; Convert the result of the order to a new List, assign a value to DataGridView to do the data source list<student> tmplist = new list<student> (); Tmplist = Sortedstudentlist. Tolist<student> (); This.dataGridView1.DataSource = tmplist; //Method Two ienumerable<student> query = Liststudent.orderby (st=> St. Age); tmplist = query. Tolist<student> (); This.dataGridView1.DataSource = tmplist; }
C # list result set ordering