Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定一个实体,有两个字段,int? 和字符串:
EntityId Name -------- ----- 1 Name1 2 Name2 3 Name3 4 Name4 (null) Name5 6 Name6 7 Name7
使用 LINQ,我如何选择前 4 个实体,直到空值之前?
似乎是一个案例TakeWhile:
TakeWhile
var query = entities.TakeWhile(x => x.EntityId != null);
(添加ToList()或ToArray()酌情)。
ToList()
ToArray()