在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ListObjectSort { public class Program { public static void Main(string[] args) { List<Student> list = new List<Student>(); Student stu1 = new Student() { Number = 4, Name = "石敏媛" }; list.Add(stu1); Student stu2 = new Student() { Number = 2, Name = "梁秀秀" }; list.Add(stu2); Student stu3 = new Student() { Number = 3, Name = "苏敏敏" }; list.Add(stu3); Student stu4 = new Student() { Number = 1, Name = "褚丽丽" }; list.Add(stu4); DisplayInfomation(list); Comparison<Student> compari = new Comparison<Student>(Compart); list.Sort(compari); DisplayInfomation(list); } public static void DisplayInfomation(List<Student> list) { Console.WriteLine("--------------------------"); foreach (Student stu in list) { Console.WriteLine(stu.Number + "\t\t" + stu.Name); } Console.WriteLine("--------------------------"); } public static int Compart(Student stu1, Student stu2) { int result = 0; CaseInsensitiveComparer objCompare = new CaseInsensitiveComparer(); result = objCompare.Compare(stu1.Number, stu2.Number); return result; } } public class Student { public int Number { get; set; } public string Name { get; set; } } }
|
请发表评论