我怎样才能做到这一点
我的第一份名单
List<string> lstParams = new List<string> { "Home", "Computer", "Fishing" };
List<string> lstIgnore_If_Have = new List<string> { "me", "hi" };现在,我想检查lstParams每个元素,如果元素有lstIgnore_If_Have的任何对象,请不要选择它。
结果lstParams如下所示
“计算机”
如何编写这样的linq查询?
我做了下面,但我不能完成它
lstParams = lstParams
.Where(pr => pr.Contains( lstIgnore_If_Have )) == false).ToList<string>();发布于 2014-08-29 01:36:53
给你:
var v = lstParams.Where (p => ! lstIgnore_If_Have.Any(i=> p.Contains(i)));只需确保第一个列表中没有包含第二个列表(使用Any)。
其结果是“计算机”。
发布于 2014-08-29 01:44:11
你可以用:
lstParams = lstParams.Where( x => lstIgnore_If_Have.All( s => !x.Contains( s ) ))
.ToList();https://stackoverflow.com/questions/25560435
复制相似问题