Using lambda expressions with TPL and LINQ
There are several methods in TPL that take a System.Func<TResult>
or System.Action
delegate as an input parameter. These can be used to pass custom logic into a task, query, or parallel loop. Inline blocks can be used when creating delegates.
Use Func
delegates to encapsulate methods that return a value and use Action
delegates to encapsulate methods that do not return values. Let’s review the following example:
static void FuncAction()
{
int[] numbers = { 15, 10, 12, 17, 11, 13, 16,
14, 18 };
int additionResult = 0;
...