O'Reilly logo

C# Multithreaded and Parallel Programming by Rodney Ringler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Delegates and lambda expressions

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required