I know that using Action as a method parameter will allow to use lambdas with that method, but what kinds of situations would come up where I would need to use that (or want to use that) in LOB applications/web applications? I believe that LINQ uses it heavily, but I just can’t see how I could use it in my own code without making things awkward or unnecessarily complex.
Does the need to use Action as a method parameter arise often and I just can’t see it (yet) or is it something that is rarely used in LOB applications?
One example is if you have a long-running operation and you want to provide progress feedback to the user:
Of course, you could also do this using events but this way it is easy to see that the callback relates to this method. If you had a large class you may not want to add another event just for a single method.
Another example might be if you want to allow the caller to mutate each value of an operation. For this you’d use Func<> which is analogous to Action but returns a value: