下面的代码有什么问题?
var newContextElementCollection = new List<NewContextElements>();
var res = from eleCollection in newContextElementCollection
where eleCollection.Property.Except(new List<string> { "Password", "Some Other Value" })
select eleCollection;
NewContextElementCollection
类:
public class NewContextElements
{
public string Property { get; set; }
public string Value { get; set; }
}
我收到此错误:
实例参数:无法从'string'转换为 'System.Linq.IQueryable' 错误2'字符串'不包含“除外”的定义和最佳扩展名 方法重载'System.Linq.Queryable.Except(System.Linq.IQueryable,
System.Collections.Generic.IEnumerable)'有一些无效的参数
答案 0 :(得分:0)
Property
是一个字符串,而不是IEnumerable<string>
,这是您的Except
子句可以使用的。
var res= from eleCollection in newContextElementCollection
where eleCollection.Property != "Password"
select eleCollection;
答案 1 :(得分:0)
var excluded = new List<string> { "Password","Some Other Value" };
var res = newContextElementCollection.Where(m => !excluded.Contains(m.Property));