Filter Linq EXCEPT on properties

前端 未结 8 1326
南方客
南方客 2020-12-04 17:45

This may seem silly, but all the examples I\'ve found for using Except in linq use two lists or arrays of only strings or integers and filters them based on the

8条回答
  •  孤城傲影
    2020-12-04 18:09

    ColinE's answer is simple and elegant. If your lists are larger and provided that the excluded apps list is sorted, BinarySearch may prove faster than Contains.

    EXAMPLE:

    unfilteredApps.Where(i => excludedAppIds.BinarySearch(i.Id) < 0);
    

提交回复
热议问题