开发者

Remove content of list from another list

开发者 https://www.devze.com 2022-12-31 13:13 出处:网络
How do I remove the content of one list from anot开发者_开发问答her list?list1.RemoveAll(i => list2.Contains(i));

How do I remove the content of one list from anot开发者_开发问答her list?


list1.RemoveAll(i => list2.Contains(i));


List<object> result = anotherlist.Except(list).ToList();


Here is a short addition and advise to James post.

If you are using List<T> and the myOtherList contains many items you should convert it to a Hashset<T> var set = new Hashset(myOtherList), so his solution should run much faster.

0

精彩评论

暂无评论...
验证码 换一张
取 消