O'Reilly logo

Microsoft® Visual C#® 2008 Step by Step by John Sharp

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

Lambda Expressions and Delegates

All the examples of adding a method to a delegate that you have seen so far use the method's name. For example, returning to the automated factory scenario described earlier, you add the StopFolding method of the folder object to the stopMachinery delegate like this:

this.stopMachinery += folder.StopFolding;

This approach is very useful if there is a convenient method that matches the signature of the delegate, but what if this is not the case? Suppose that the StopFolding method actually had the following signature:

void StopFolding(int shutDownTime); // Shut down in the specified number of seconds

This signature is now different from that of the FinishWelding and PaintOff methods, and therefore you cannot use the ...

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