我在where子句“ _list.Where<T>(whereClause) ”上遇到3个错误如何解决?
错误 1
'System.Collections.Generic.List<FuncMetodunuTaniyalim3.DataModel.Customer>' 不包含 'Where' 的定义和最佳扩展方法重载 'System.Linq.ParallelEnumerable.Where<TSource>(System.Linq.ParallelQuery <TSource>, System.Func<TSource,int,bool>)' 有一些无效参数
错误 2实例参数:无法从 'System.Collections.Generic.List<FuncMetodunuTaniyalim3.DataModel.Customer>' 转换为 'System.Linq。 ParallelQuery<T>'
错误 3参数 2:无法从 'System.Func<T,bool>' 转换为 'System.Func<T,int,bool>'
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FuncMetodunuTaniyalim3
{
public class Search<T> where T : class
{
private List<DataModel.Customer> _list;
public Search()
{
_list = new List<DataModel.Customer>();
}
public int Find(Func<T, bool> whereClause)
{
return _list.IndexOf(_list.Where<T>(whereClause).FirstOrDefault<T>());
}
}
//Repository
public class DataModel
{
private IEnumerable<Customer> customers;
public List<Customer> Customers
{
get { return customers.ToList(); }
}
public DataModel()
{
customers = new[] { new Customer(){ Id=1, Name="cbfghg", SurName="hfh", Age=29, Dept=0, Income=100},
new Customer(){ Id=2, Name="hfghfhf", SurName="erhfghfhfhem", Age=0,Dept=45, Income=300},
new Customer(){ Id=3, Name="hgfhgfhf", SurName="balhfghgfhfgh", Age=33, Dept=20, Income=150}};
}
//Model
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public string SurName { get; set; }
public int Age { get; set; }
public int Income { get; set; }
public int Dept { get; set; }
public Customer()
{
}
}
}
}