
xii | Table of Contents
9. Delegates, Events, and Anonymous Methods
. . . . . . . . . . . . . . . . . . . . . . . . .
486
9.1 Controlling When and If a Delegate Fires Within
a Multicast Delegate 487
9.2 Obtaining Return Values from Each Delegate
in a Multicast Delegate 490
9.3 Handling Exceptions Individually for Each Delegate
in a Multicast Delegate 492
9.4 Converting Delegate Invocation from Synchronous to Asynchronous 496
9.5 Wrapping Sealed Classes to Add Events 499
9.6 Passing Specialized Parameters to and from an Event 506
9.7 An Advanced Interface Search Mechanism 512
9.8 An Advanced Member Search Mechanism 515
9.9 Observing Additions and Modifications to a Hashtable 520
9.10 Using the Windows Keyboard Hook 528
9.11 Tracking and Responding to the Mouse 535
9.12 Using Anonymous Methods 536
9.13 Set Up Event Handlers Without the Mess 541
9.14 Using Different Parameter Modifiers in Anonymous Methods 545
9.15 Using Closures in C# 548
9.16 Performing Multiple Operations on a List Using Functors 552
10. Regular Expressions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
557
10.1 Enumerating Matches 558
10.2 Extracting Groups from a MatchCollection 561
10.3 Verifying the Syntax of a Regular Expression 564
10.4 Quickly Finding Only the Last Match in a String 566
10.5 Replacing Characters or Words in a String 566
10.6 Augmenting the Basic String Replacement Function ...