I acknowledge that they can be useful, but I’m trying to wrap my head around when I would actually want to have a func as a parameter of a method.
public void WeirdMethod(int myNumber, func op);
In terms of design and functionality, could someone explain to me some circumstances where I would want to consider this? Theories of “reusability” isn’t going going to help me much. Real world scenarios would be best. Help me think like you lol.
Here’s about all I know:
- This would allow me to pass a delegate
- This would allow me to use a lambda expression.
Yeap…
NOTE:
I know this thread will get closed since there’s no “right” answer. But I think what clicked it for me just now was “delayed calculation”.
A general scenario is when you must pass a delayed calculation to your method. This is useful when calculating something is expensive, for example, when you cache something.
Now you can call this method as follows: