About This eBook by Bart De Smet

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Delegate Instances

Although delegate types provide a type-safe way to refer to methods, instances concretize this notion by referring to a particular method on some object (or using null for a static method). In our running example, we give a first example of instantiating a delegate instance:

static void Main() {    BinOp add = new BinOp(Add);    int three = add(1, 2); // calls the Add method through the delegate}

This is one possible way to create a delegate instance that has been supported since the early C# 1.0 days. As shown in Figure 17.6, Visual Studio hints at the required method signature for the delegate target.

FIGURE 17.6 IntelliSense for instantiation of a delegate type.

Since C# 2.0, the syntax for ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required