Higher-Order Functions C# with Example



Higher-Order Functions C# with Example

A higher-order function is one that takes another function as an argument or returns a function (or both). 
This is commonly done with lambdas, for example when passing a predicate to a LINQ Where clause: 
var results = data.Where(p => p.Items == 0); 
The Where() clause could receive many different predicates which gives it considerable flexibility. 
Passing a method into another method is also seen when implementing the Strategy design pattern. For example, 
various sorting methods could be chosen from and passed into a Sort method on an object depending on the 
requirements at run-time. 

0 Comment's

Comment Form

Submit Comment