13
Delegates and Lambda Expressions
Previous chapters discussed extensively how to create classes to encapsulate data and operations on data. As you create more and more classes, you will see common patterns in the relationships among them. One common pattern is to pass an object to a method solely so that the method can, in turn, call a method on the object. For example, if you pass an IComparer<int>
reference to a method, odds are good that the called method will itself call the Compare()
method on the object you provided. In this case, the interface is nothing more than a way to pass a reference to a single method that can be invoked. Consider a second example in which you invoke a new process. Rather than blocking or repeatedly checking ...
Get Essential C# 12.0, 8th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.