Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>1) Those descriptions sound pretty accurate to me. Sometimes anonymous methods and lambda expressions will need to create a new type to put the target of the delegate in, so they can act as <a href="http://csharpindepth.com/Articles/Chapter5/Closures.aspx" rel="nofollow noreferrer">closures</a>.</p> <p>2/3) I would read up a bit until you're happy with delegates, anonymous methods and lambda expressions. I dedicate a chapter to the delegate-related changes in each of C# 2.0 and C# 3.0 in C# in Depth, although of course other books go into detail too. I have an <a href="http://pobox.com/~skeet/csharp/events.html" rel="nofollow noreferrer">article</a> as well, if that helps.</p> <p>As for examples - delegates are used for many different purposes. They're all different ways of looking at the same functionality, but they can <em>feel</em> very different:</p> <ul> <li>Providing the code to call when you start a new thread</li> <li>Reacting to UI events</li> <li>Providing the filter, selection, ordering etc for a LINQ query</li> <li>Providing a callback for when an asynchronous operation has finished</li> </ul> <p>If you have any specific situations you'd like an example of, that would be easier to answer.</p> <p>EDIT: I should point out that it's good news that you're only working with LINQ to Objects and LINQ to XML at the moment, as that means you don't need to understand expression trees yet. (They're cool, but one step at a time...) LINQ to XML is really just an XML API which works nicely with LINQ - from what I remember, the only times you'll use delegates with LINQ to XML are when you're actually calling into LINQ to Objects. (That's very nice to do, admittedly - but it means you can reuse what you've already learned.)</p> <p>As you've already got C# in Depth, chapters 10 and 11 provide quite a few examples of <em>using</em> lambda expressions (and query expressions which are translated into lambda expressions) in LINQ. Chapter 5 has a few different examples of delegate use.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload