How can we use delegates for abstraction? We can also use interfaces for abstraction so which is better? Is it with using interfaces or using delegates.
A simple practical example will help.
Thankyou.
How can we use delegates for abstraction? We can also use interfaces for abstraction so which is better? Is it with using interfaces or using delegates.
A simple practical example will help.
Thankyou.
To answer the question in part, please consider the generic Linq extension method OrderBy
, which is documented here. It is possible to use a delegate to provide a mapping from the sequence members to a type which is then used for the comparison proper. Hence, the actual sorting is decoupled from the ordering which is implicitly given via the implementation of the result type. The used delagate type permits a more abstract implementation of the sorting algorithm.