Why this code doesn’t work?
public static IList<float> CreateModifiedList(IList<float> list)
{
IList<float> modifiedList= list.Aggregate(new List<float> (), (l, item) =>l.Add(++item));
return modifiedList;
}
When I try to compile it using Mono I get the following error:
error CS0029: Cannot implicitly convert type
void' toSystem.Collections.Generic.List’
It does not work, because
l.Add(++item)is not returning your aggregate (list of float) – it returnsvoid. Second argument should be of typeFunc<List<float>, float, List<float>>. Change your code to return aggregation variable:(l, item) => { l.Add(++item); return l; }BTW What you are doing could be achieved this way: