Examples from Chapter 9 (Delegates, Lambdas, and Events) of Programming C# 10.0 (O'Reilly).
- Example 2. Method with a delegate parameter
- Example 3. The Predicate<T> delegate type
- Example 4. Creating a delegate
- Example 5. Constructing a delegate
- Example 6. Implicit delegate construction
- Example 7. Delegates to methods in another class
- Example 8. Implicit instance delegate
- Example 9. Explicit instance delegate
- Example 10. CreateDelegate
- Example 11. Combining delegates
- Example 12. Invoking a delegate
- Example 13. The first few Action delegates
- Example 14. The first few Func delegates
- Example 15. Delegate covariance
- Example 16. Illegal delegate conversion
- Example 17. The members of a delegate type
- Example 18. Using Invoke explicitly
- Example 19. Using Invoke with the null-conditional operator
- Example 20. Anonymous method syntax
- Example 21. Lambda syntax
- Example 22. Lambda variations
- Example 23. A zero-argument lambda
- Example 24. Ignoring arguments in an anonymous method
- Example 25. A lambda discarding its arguments
- Example 26. Using a variable from the containing method
- Example 27. Using a variable from the containing method (expression-bodied)
- Example 28. Where value comes from
- Example 29. Code generated for an anonymous function
- Example 30. Modifying a captured variable
- Example 31. Premature disposal
- Example 32. Opting out of variable capture with
static
- Example 33. Problematic variable capture in a for loop
- Example 34. Modifying a loop to capture the current value
- Example 35. Capturing variables at different scopes
- Example 36. A lambda expression
- Example 37. What the compiler does with a lambda expression
- Example 38. Expressions and database queries
- Example 39. Use of lambda expressions by the Moq library