c# - Lambda expression as function parameter -
i have following code
list<int> getindices<t>(list<t> list, ?????? condition { var result = list .select((p, index) => index) .where(condition); return result.tolist(); }
and call getindices(somelist, (p, index) => (somelist[index].height < somelist[index - 1].height))
what correct type of condition
?
there's error in code: where
expects delegate returns bool
value , has list element type input.
var result = list .select((p, index) => index) // projects element it's index (of type int) .where(condition); // => expects func<int, bool>
so need func<int,bool>
however, spec think want func<t,int,bool>
, means have rewrite implementation of getindices
as
var result = list .select((p, index) => new {p, index}) .where(x => condition(x.p, x.index)) .select(x => x.index);
Comments
Post a Comment