我有一个条件列表,我想在C#中使用linq做这样的事情:
var filtred_list = oldList.Where(
foreach (int condition in conditions) {
c => c.attribut == condition;
}
);
谢谢
答案 0 :(得分:2)
在您的情况下,转换where语句就足够了:
var filtred_list = oldList.Where(
c => conditions.Contains(c.attribut);
}
);
答案 1 :(得分:0)
使用IEnumerable<T>.Contains(T)
方法:
var filtred_list = oldList.Where(c => conditions.Contains(c.attribut));
或
var filtred_list = from o in oldList
where conditions.Contains(o.attribut)
select o;
答案 2 :(得分:0)
var filtred_list = oldList.Where(x => conditions.Any(c => c.attribut == x));