Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从另一个列表中删除其字符串包含子字符串的列表元素_C#_Linq - Fatal编程技术网

C# 如何从另一个列表中删除其字符串包含子字符串的列表元素

C# 如何从另一个列表中删除其字符串包含子字符串的列表元素,c#,linq,C#,Linq,我有这样一个字符串: var str = "DAVID CORPORATION" 然后我有一个我不想在str中使用的子字符串列表 var describers = new List<string> {"CORP", "INC", "LTD", "TECH", "ENGINEER", "LLC","MICROELE"}; 现在,我想删除该列表中包含描述符中的子字符串的所有项。我发现这种方法在互联网上做了无数次 strList.RemoveAll(x => describers

我有这样一个字符串:

var str = "DAVID CORPORATION"
然后我有一个我不想在str中使用的子字符串列表

var describers = new List<string> {"CORP", "INC", "LTD", "TECH", "ENGINEER", "LLC","MICROELE"};
现在,我想删除该列表中包含描述符中的子字符串的所有项。我发现这种方法在互联网上做了无数次

strList.RemoveAll(x => describers.Contains(x));
这不起作用,因为它所做的只是检查描述符是否包含strList的整个单词。我需要它反向工作

这不起作用,但它是一个算法,我希望它如何工作

strList.RemoveAll(x => x.Contains(describers.Any()));
无法从“bool”转换为“string”

当然,但是如何从描述符中删除strList中包含子字符串项的项


…而且只在一个林克兰巴。我试图避开foreach/for/do循环。

您可以使用
Any
执行以下操作:

strList.RemoveAll(x => describers.Any(d => x.Contains(d)));

您可以使用
Any
执行以下操作:

strList.RemoveAll(x => describers.Any(d => x.Contains(d)));

工作,谢谢。工作,谢谢。