C#之对象数组排序
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 对象数组排序测试 { class Program { delegate bool Sort(Passen ps1, Passen ps2); static void Main(string[] args) { Passen[] passenArray = { new Passen() { Name = "刘冠", Age = "23" }, new Passen() { Name = "王莉", Age = "22" }, new Passen() { Name = "小明", Age = "33" } }; Passen maxPas = Function(passenArray, (pass1, pass2)=>{ if(String.Compare(pass1.Age, pass2.Age) > 0) { return true; } else { return false; } }); Console.WriteLine(maxPas); Console.ReadKey(); } static Passen Function(Passen[] pass, Sort sort) { Passen maxPassen = pass[0]; for(int i = 1; i < pass.Length; i++) { if(sort(pass[i], maxPassen)) { maxPassen = pass[i]; } } return maxPassen; } } class Passen { public string Name { get; set; } public string Age { get; set; } } }