Saturday, 10 March 2018

Linq – Action vs Func vs Predicate in C#

The purpose of writing this article is simple; to provide a simple and fresh demonstration of Action vs Func vs Predicate keyword in C#.
Though widely used with Linq, Action and Func are concepts logically independent of Linq. C++ already contained the basic concept in form of typed function pointers.
  • Action is a delegate (pointer) to a method, that takes zero, one or more input parameters, but does not return anything.
  • Func is a delegate (pointer) to a method, that takes zero, one or more input parameters, and returns a value (or reference).
  • Predicate is a function pointer for method which returns boolean value. They are commonly used for iterating a collection or to verify if the value does already exist.

Here is a small example for Action, Func and Predicate without using Linq

No comments:

Post a Comment