Currently i am creating an extension method that accepts parameters. Using the below example, how could one convert this using lambda expressions?
public static decimal ChangePercentage(this IEnumerable<Trade> trades, DateTime startDate, DateTime endDate)
{
var query = from trade in trades
where trade.TradeTime >= startDate
where trade.TradeTime <= endDate
orderby trade.TradeTime descending
select trade;
return (query.First().Value - query.Last().Value) / query.First().Value * 100;
}
What are the pro/cons using lambda vs normal method parameters?
Thanks
One way you could change the sample to use lambda expressions is to use a filter.
The biggest pro this gives you is flexbility. Instead of having a method which does date based filtering for calculation. You have a method with a flexible filter method for calculating percentages.