Technical tips-Delegate, Action, Func and Predicate

416

Delegate, Action, Func and Predicate. Simple explanation:

A delegate is a type-safe function pointer that can reference a method that has the same signature as that of the delegate. Delegates are used to define callback methods and implement event handling, and they are declared using the “delegate” keyword. You can declare a delegate that can appear on its own or even nested inside a class.

What are Func and Action delegates? How can they be used?

The basic difference between Func and Action delegates is that while the former is used for delegates that return value, the latter can be used for those delegates in which you don’t have any return value.

Func is a delegate that points to a method that accepts one or more arguments and returns a value. Action is a delegate that points to a method which in turn accepts one or more arguments but returns no value. In other words, you should use Action when your delegate points to a method that returns void.
A Predicate is a delegate that accepts one or more generic parameters and returns a Boolean value — you can assume it something like Func<T,bool>. Predicate delegates are typically used to perform search operations on some data based on a set of criteria.

http://www.infoworld.com/article/3057152/application-development/how-to-work-with-action-func-and-predicate-delegates-in-c.html

https://blogs.msdn.microsoft.com/brunoterkaly/2012/03/02/c-delegates-actions-funcs-lambdaskeeping-it-super-simple/

Lambda:

 

SHARE
Previous articlePushSharp
Next articleCSS Trick 1