In this chapter, we have used delegates and lambda expressions. These two concepts are confusing for some new developers, so let's take a moment to discuss them in a little more detail.
Delegates are often used when creating event handlers. A delegate defines a reference type that encapsulates a method with a certain set of parameters and a return type. It functions a lot like a function pointer in C++. It allows us to pass a delegate object that can be used to call a method without having to know the method at compile time.
In our example, the
Task constructor takes an
Action delegate to define the action to be performed by the task. In our example, we set the method for the delegate in the constructor definition, ...