i face to face 3 errors on where clause”_list.Where<T>(whereClause) ” how to solve it?
Error 1
‘System.Collections.Generic.List<FuncMetodunuTaniyalim3.DataModel.Customer>’ does not contain a definition for ‘Where’ and the best extension method overload ‘System.Linq.ParallelEnumerable.Where<TSource>(System.Linq.ParallelQuery<TSource>, System.Func<TSource,int,bool>)’ has some invalid arguments
Error 2 Instance argument: cannot convert from ‘System.Collections.Generic.List<FuncMetodunuTaniyalim3.DataModel.Customer>’ to ‘System.Linq.ParallelQuery<T>’
Error 3 Argument 2: cannot convert from ‘System.Func<T,bool>’ to ‘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()
{
}
}
}
}
Your Search class contains a
List<Customer>. Probably you meant to useList<T>: