我正在尝试从列表中查找一个字符串....似乎它不工作,如果我有List<string>
它确实工作..意思像下面的代码......
List<string> c = new List<string>();
c.Add("John Doe"));
c.Add("Erich Schulz"));
//我认为Criterion类的问题?这是我的班级结构:
public class Criterion
{
public Criterion(String propertyName, object value)
{
this.PropertyName = propertyName;
this.Value = value;
}
}
//here is the method...
public static List<Criterion> LoadNames()
{
List<Criterion> c = new List<Criterion>();
c.Add(new Criterion("Name1", "John Doe"));
c.Add(new Criterion("Name2", "Erich Schulz"));
return c;
}
这是我试图使其工作的代码:
bool isExists = LoadNames.Any(s=> "Erich Schulz".Contains(s));
错误:
不包含“任何”的定义和最佳扩展方法重载'System.Linq.Enumerable.Any<TSource>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,bool>)' has some invalid arguments