About This eBook by Bart De Smet

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

O'Reilly logo

Invoking Delegates

Creating delegate instances to refer to particular methods is a necessary step toward invoking those methods through the delegate. In passing, we’ve shown the way to do such invocations repeatedly: They just look like ordinary method calls. For example:

Func<int, int, int> add = (a, b) => a + b;int three = add(1, 2);

IntelliSense in Visual Studio will obviously give the caller a hand by showing what arguments are expected. Notice that names for those arguments come from the delegate type that’s being used. In the preceding example, we’re using one of the generic Func types, where arguments have names like arg1 and arg2. How this looks in Visual Studio is shown in Figure 17.10.

FIGURE 17.10 Invoking ...

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