0

下面的代码有什么问题?

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 'string' 不包含 'Except' 的定义和最佳扩展方法重载 'System.Linq.Queryable.Except(System.Linq.可查询,

System.Collections.Generic.IEnumerable)' 有一些无效参数

4

2 回答 2

0

Property是一个字符串,而不是一个IEnumerable<string>,这是您的Except子句可以处理的。

var res= from eleCollection in newContextElementCollection
     where eleCollection.Property !=  "Password"
     select eleCollection;
于 2012-05-10T09:16:19.510 回答
0
var excluded = new List<string> { "Password","Some Other Value" };
var res = newContextElementCollection.Where(m => !excluded.Contains(m.Property));
于 2012-05-10T10:42:13.567 回答