I have the following method in an assembly:
public string dostuff(string foo, object bar = null) { /* ... */ }
I use it as a callback, so a
You'll need to create a new method that accepts only one argument, and that passes the default value for the second argument. You could do this with a lambda, rather than creating a new named method, if you wanted:
Func doStuffDelegate = s => dostuff(s);
The other option would be to use a delegate who's signature has an optional second argument, instead of using Func
, in which case your method's signature would match:
public delegate string Foo(string foo, object bar = null);
You could assign dostuff
to a delegate of type Foo
directly, and you would be able to specify only a single parameter when invoking that delegate.