question

RonaldRex-2335 avatar image
0 Votes"
RonaldRex-2335 asked Bruce-SqlWork answered

When to use Func, Action And Predicate Delegates

Hi Friends. I just wanted to ask a question in regards to what areas or components in software architecture or development are best suited for using Func, Action And Predicate Delegates. Thanks for any articles or references to blogs.

dotnet-csharpdotnet-adonet
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered

they are used to implement a callback. callbacks are common in the following patterns (but not limited to)

Visitor Pattern: http://en.wikipedia.org/wiki/Visitor_pattern
Observer Pattern: http://en.wikipedia.org/wiki/Observer_pattern
Strategy Pattern: http://en.wikipedia.org/wiki/Strategy_pattern

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JackJJun-MSFT avatar image
0 Votes"
JackJJun-MSFT answered

@RonaldRex-2335, Welcome to Microsoft Q&A,

If you want to return one result with zero, one or more input parameters, you could use Func Delegate.

If you don't want to return result with zero, one or more input parameters, you could use Action Delegate.

If you want to return a bool type result with zero, one or more input parameters, you could use Predicate Delegate.

You could refer to the following links to know more about it.

Func vs. Action vs. Predicate

Delegates: Predicate vs. Action vs. Func



Best Regards,
Jack




If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.