zoukankan      html  css  js  c++  java
  • lambda表达式嵌套

     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="?"的那一行数据

  • 相关阅读:
    7
    6
    5.1
    5
    C#类库帮助类
    Asp.net 数据库依赖那些事
    C#使用NLog记录日志
    JQuery常用操作实现方式
    常用Sql 标量值函数
    Sql语句查询XML
  • 原文地址:https://www.cnblogs.com/YCconfig/p/5798018.html
Copyright © 2011-2022 走看看