I am trying to create a method where I can pass a Linq
expression as a parameter to return a new list of items.
Currently I am doing this (based off this answer):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
class Collection<T> {
List<T> items = new List<T>();
public Collection<T> Filter(Expression<Func<T, bool>> query) {
Collection<T> c = new Collection<T>();
c = items.Where(query);
return c;
}
}
'List' does not contain a definition for 'Where' and the best extension method overload 'Queryable.Where(IQueryable, Expression>)' requires a receiver of type 'IQueryable'
I am not exactly sure what to do here to fix this.