13.07.2015 Views

C# in Depth

C# in Depth

C# in Depth

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Fast-tracked delegatesThis chapter covers■■■■■Longw<strong>in</strong>ded <strong>C#</strong> 1 syntaxSimplified delegate constructionCovariance and contravarianceAnonymous methodsCaptured variablesThe journey of delegates <strong>in</strong> <strong>C#</strong> and .NET is an <strong>in</strong>terest<strong>in</strong>g one, show<strong>in</strong>g remarkableforesight (or really good luck) on the part of the designers. The conventions suggestedfor event handlers <strong>in</strong> .NET 1.0/1.1 didn’t make an awful lot of sense—until<strong>C#</strong> 2 showed up. Likewise, the effort put <strong>in</strong>to delegates for <strong>C#</strong> 2 seems <strong>in</strong> some waysout of proportion to how widely used they are—until you see how pervasive theyare <strong>in</strong> idiomatic <strong>C#</strong> 3 code. In other words, it’s as if the language and platformdesigners had a vision of at least the rough direction they would be tak<strong>in</strong>g, yearsbefore the dest<strong>in</strong>ation itself became clear.Of course, <strong>C#</strong> 3 is not a “f<strong>in</strong>al dest<strong>in</strong>ation” <strong>in</strong> itself, and we may be see<strong>in</strong>g furtheradvances for delegates <strong>in</strong> the future—but the differences between <strong>C#</strong> 1 and<strong>C#</strong> 3 <strong>in</strong> this area are startl<strong>in</strong>g. (The primary change <strong>in</strong> <strong>C#</strong> 3 support<strong>in</strong>g delegates is<strong>in</strong> lambda expressions, which we’ll meet <strong>in</strong> chapter 9.)137Licensed to Rhona Hadida

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!