staticvoidtest_person_sort() { List<Person> list = new List<Person>() { new Person(){name="a",age=15,id=1 }, new Person(){name="b",age=12,id=2 }, new Person(){name="c",age=14,id=3 }, new Person(){name="d",age=12,id=4 }, new Person(){name="e",age=14,id=5 }, new Person(){name="f",age=12,id=6 }, new Person(){name="g",age=15,id=7 }, }; print_array(list);
staticvoidtest_person_sort_() { List<Person> list = new List<Person>() { new Person(){name="a",age=15,id=1 }, new Person(){name="b",age=12,id=2 }, new Person(){name="c",age=14,id=3 }, new Person(){name="d",age=12,id=4 }, new Person(){name="e",age=14,id=5 }, new Person(){name="f",age=12,id=6 }, new Person(){name="g",age=15,id=7 }, }; print_array(list);
staticvoidtest_person_linq() { List<Person> list = new List<Person>() { new Person(){name="a",age=15,id=1 }, new Person(){name="b",age=12,id=2 }, new Person(){name="c",age=14,id=3 }, new Person(){name="d",age=12,id=4 }, new Person(){name="e",age=14,id=5 }, new Person(){name="f",age=12,id=6 }, new Person(){name="g",age=15,id=7 }, }; print_array(list); // 1. 方式一 IEnumerable<Person> query = from d in list orderby d.age select d; // 2. 方式二 query = list.OrderBy(x => x.age); print_array(query); }
staticvoidtest_person_linq_() { List<Person> list = new List<Person>() { new Person(){name="a",age=15,id=1 }, new Person(){name="b",age=12,id=2 }, new Person(){name="c",age=14,id=3 }, new Person(){name="d",age=12,id=4 }, new Person(){name="e",age=14,id=5 }, new Person(){name="f",age=12,id=6 }, new Person(){name="g",age=15,id=7 }, }; print_array(list); // 1. 方式一 IEnumerable<Person> query = from d in list orderby d.age descending select d; // 2. 方式二 query = list.OrderByDescending(x => x.age); print_array(query); }
staticvoidtest_person_linq_more() { List<Person> list = new List<Person>() { new Person(){name="a",age=15,id=1 }, new Person(){name="b",age=12,id=2 }, new Person(){name="c",age=14,id=3 }, new Person(){name="d",age=12,id=4 }, new Person(){name="e",age=14,id=5 }, new Person(){name="f",age=12,id=6 }, new Person(){name="g",age=15,id=7 }, }; print_array(list); // 1. 方式一 IEnumerable<Person> query = from d in list orderby d.age, d.id select d; // 2. 方式二 query = list.OrderBy(x => x.age).ThenBy(x => x.id); print_array(query); }
staticvoidtest_person_linq_more_() { List<Person> list = new List<Person>() { new Person(){name="a",age=15,id=1 }, new Person(){name="b",age=12,id=2 }, new Person(){name="c",age=14,id=3 }, new Person(){name="d",age=12,id=4 }, new Person(){name="e",age=14,id=5 }, new Person(){name="f",age=12,id=6 }, new Person(){name="g",age=15,id=7 }, }; print_array(list);
// 1. 方式一 IEnumerable<Person> query = from d in list orderby d.age descending, d.id descending select d; // 2. 方式二 query = list.OrderByDescending(x => x.age).ThenByDescending(x => x.id); print_array(query); }