How to subtract one huge list from another efficiently in C#

后端 未结 4 872
天命终不由人
天命终不由人 2021-02-07 00:09

I have a very long list of Ids (integers) that represents all the items that are currently in my database:

var idList = GetAllIds();

I also hav

4条回答
  •  逝去的感伤
    2021-02-07 00:49

    Transform temporarily idList to an HashSet and use the same method i.e.:

    items.RemoveAll(e => idListHash.Contains(e.Id));
    

    it should be much faster

提交回复
热议问题