Free mag vol1 | Page 19

 CONTENTS Creating Custom Generic Structures and Classes .........................................................353 The default Keyword in Generic Code .................................................................................................. 354 Constraining Type Parameters ......................................................................................355 Examples Using the where Keyword .................................................................................................... 356 The Lack of Operator Constraints ......................................................................................................... 357 Summary .......................................................................................................................358  Chapter 10: Delegates, Events, and Lambda Expressions ..................................359 Understanding the .NET Delegate Type .........................................................................359 Defining a Delegate Type in C# ............................................................................................................ 360 The System.MulticastDelegate and System.Delegate Base Classes.................................................... 362 The Simplest Possible Delegate Example......................................................................364 Investigating a Delegate Object............................................................................................................ 365 Sending Object State Notifications Using Delegates .....................................................367 Enabling Multicasting ........................................................................................................................... 370 Removing Targets from a Delegate’s Invocation List ........................................................................... 371 Method Group Conversion Syntax ........................................................................................................ 372 Understanding Generic Delegates .................................................................................374 The Generic Action<> and Func<> Delegates..................................................................................... 375 Understanding C# Events...............................................................................................378 The C# event Keyword.......................................................................................................................... 379 Events Under the Hood ......................................................................................................................... 380 Listening to Incoming Events ............................................................................................................... 381 Simplifying Event Registration Using Visual Studio.............................................................................. 383 Creating Custom Event Arguments....................................................................................................... 384 The Generic EventHandler Delegate .............................................................................................. 386 Understanding C# Anonymous Methods........................................................................387 Accessing Local Variables .................................................................................................................... 389 xvii