I have a method like this:
public List<Fruit> Traverse (IEnumerable<Fruit> collection, Action<Fruit> action)
I can do this:
Traverse (array, f => f.Text);
How can I call the action so I get the same element?
Traverse (array, f => f);
C# compiler doesn't allow me to do this.
EDIT:
List<Fruit> result = ...
foreach (Fruit fruit in collection)
{
result.Add(fruit);
action(fruit);
}
The method signature is fixed so I can't get anything else by just using an action, right? But what I need is to pass an action that does nothing so I get the whole result list.