b = () => "other string...">

Real example Func <sometype> + Func <sometype>

Let's say you have:

Func<string> a = () => "string here";
Func<string> b = () => "other string here";

var c = a + b;

      

What is the real world for?

+3


source to share


1 answer


The only time I can think this is useful is if you are actually going to treat it as a list of delegates (via Delegate.GetInvocationList

) and call each one separately. For example, you can do this for validators, where each validation step might return null

"valid" or an error message otherwise. This would be very rare to do, though.



The predominant use for a combination of delegates - for event handlers - where usually the delegate type is compatible with EventHandler

(with the return type void

). At this point, the behavior of multi-leaf delegates returning the result of the last invoked action is irrelevant, since there is no return value anyway.

+5


source







All Articles