1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace ConsoleTest 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 var personList = new List<Person>() 14 { 15 new Person() {Name="YC1",Age=22,Sex="男" }, 16 new Person() {Name="YC2",Age=23,Sex="女" }, 17 new Person() {Name="YC3",Age=24,Sex="男" }, 18 new Person() {Name="YC4",Age=25,Sex="女" }, 19 new Person() {Name="YC5",Age=26,Sex="?" }, 20 new Person() {Name="YC6",Age=27,Sex="女" }, 21 new Person() {Name="YC7",Age=28,Sex="男" }, 22 new Person() {Name="YC8",Age=29,Sex="女" }, 23 new Person() {Name="YC9",Age=30,Sex="男" }, 24 new Person() {Name="YC10",Age=31,Sex="女" } 25 }; 26 27 var list = personList.Where(d => d.Age.Equals(personList.Where(e => e.Sex == "?").Max(e => e.Age))).ToList(); 28 29 foreach (var v in list) 30 { 31 Console.WriteLine(v.Name + "--" + v.Age + "--" + v.Sex); 32 } 33 34 Console.ReadLine(); 35 } 36 } 37 }
输出了sex="?"的那一行数据