Skip to main content
 首页 » 编程设计

c#之如何从 POCO 对象集合中检索属性的最高/最后值

2024年02月13日32zfyouxi

使用下面的示例对象...

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
 
namespace ConsoleApplication1 
{ 
    public class Worker 
    { 
        public int WorkerId { get; set; } 
    } 
} 

如何获取 List<Worker> 中的最高/最后一个值的 WorkerId属性(property)?

请您参考如下方法:

使用 LINQ:

var max = list.Max(x=>x.WorkerId);