How do I remove items from generic list, based on multiple conditions and using linq

后端 未结 2 1007
有刺的猬
有刺的猬 2021-01-11 10:48

I have two lists, one containing urls and another, containing all MIME file extensions. I want to remove from the first list all urls that point to such files.

Sampl

2条回答
  •  春和景丽
    2021-01-11 11:44

    If you want to create a new list with only the items matching your condition:

    List result = urls.Where(x => !mime.Any(y => x.EndsWith(y))).ToList();
    

    If you want to actually remove items from source, you should use RemoveAll:

    urls.RemoveAll(x => mime.Any(y => x.EndsWith(y)));
    

提交回复
热议问题