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

后端 未结 2 992
有刺的猬
有刺的猬 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:45

    here is a one liner that fits your needs

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

    maybe this is a safer appraoach

    urls.RemoveAll(x => mime.Contains(Path.GetExtension(x)));
    

    When you have URLs like http://stackoverflow.com/questions/dir/some.ashx?ID=.pdf you should think about another approach

提交回复
热议问题