IComparer定义类型为比较两个对象而实现的方法。 此方法支持排序比较 以下实例比较玩家分数的排序 public class Player:IComparer<Player> { public float scroe; public string name; public Player() { } public float Scroe { get; set; } public string Name { get; set; } public int Compare(Player x, Player y) { // return x.Scroe.CompareTo(y.Scroe);//升序排序 return y.Scroe.CompareTo(x.Scroe);//降序排序 } public override string ToString() { return "Scroe" + Scroe + "Name" + Name; } } public class Program { static void Main(string[] args) { Random random = new Random(); List<Player> players = new List<Player>(); for (int i = 0; i <20; i++) { Player player = new Player(); player.Scroe = random.Next(80,100); player.Name = "haha" + i.ToString(); players.Add(player); } IComparer<Player> comparer = new Player(); //该方法是用Sort方法进行排序 players.Sort(comparer); foreach (var item in players) { Console.WriteLine(item.ToString()); } Console.ReadKey(); } }