When to use Func, Action And Predicate Delegates

Ronald Rex 1,666 Reputation points
2022-08-29T16:42:32.26+00:00

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.

Developer technologies | .NET | Other
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-08-30T18:29:02.363+00:00

    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

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Jack J Jun 25,296 Reputation points
    2022-08-30T01:44:50.567+00:00

    @Ronald Rex , 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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.