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