开发者

Remove content of list from another list

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜