我有一个场景,我必须在 LINQ 中使用 .Select 和 where。
以下是我的查询。
List<DTFlight> testList = _ctrFlightList.Select(i => new DTFlight() { AirLineName = i.AirLineName,ArrivalDate = i.ArrivalDate }).ToList();
我想在这个查询中使用 where(add condition)。
请帮忙...
谢谢。
最佳答案
我建议你使用 Where :
List<DTFlight> testList = _ctrFlightList.
Where(ctrFlight => ctrFlight.Property > 0).
Select(i => new DTFlight() { AirLineName = i.AirLineName, ArrivalDate = i.ArrivalDate }).ToList();
Where 返回一个 IEnumerable,因此您可以在其上应用您的 Select。
关于linq - 将 Where 与 .Select Linq 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5337679/