Reputation: 41
I know that in C# you can pass a function as a parameter to another function with something that looks like this:
public bool DoSomething(int param1, int param2 = 0, Func<bool, bool> f)
{
//Do Some work
//Run function f
bool i = f(true);
return true;
}
I also know that if you initialize one of the parameters, in my example, the second parameter (int param2 = 0), then the parameter is optional.
How can I make the third parameter (the function f) as an optional parameter? What should I initialize it to?
I would appreciate some help!
Upvotes: 0
Views: 78
Reputation: 2914
public bool DoSomething(int param1, int param2 = 0, Func<bool, bool> f = null)
{
...
}
Upvotes: 3