Subtract a generic list from another

前端 未结 6 825
天涯浪人
天涯浪人 2020-12-13 23:02

I am trying remove a list of firmIDs from one list from another. I don\'t really understand linq but I am pretty sure I need to use it.

List firm         


        
6条回答
  •  清歌不尽
    2020-12-13 23:48

    From your code above, I presume you are trying to get entries from Firms that have a corresponding item in TrackedFirms.

    List results = Firms.Where(f => TrackedFirms.Any(t => t.FirmId == f.FirmId)).ToList();
    

    If on the other hand you want untracked firms, then it's :

    List results = Firms.Where(f => !TrackedFirms.Any(t => t.FirmId == f.FirmId)).ToList();
    

提交回复
热议问题