0

I have an interface that looks like this:

Task<CurrencyResponse> credit(string id, string correlationVector = null);

I have a method that takes in this credit function as a function delegate:

protected async Task PerformWalletOperation(Func<string, string, Task<CurrencyResponse>> credit)
{
    currencyResponse = await credit(id);
}

However, since my last parameter (correclationVector) is an optional argument, I get a compile error and have to pass in a value. Is there a way around this without me having to call my credit like this:

credit(id, null);
DannyD
  • 2,732
  • 16
  • 51
  • 73
  • 1
    What about creating another method `Task credit(string id)` that just calls that method using `credit(id, null)`? – Edu Sep 19 '18 at 17:48
  • I'd rather not since that credit interface is coming from an external library that I'm calling and I don't want to update that lib – DannyD Sep 19 '18 at 17:51
  • You could use `Func>` and pass `x => credit(x)` – juharr Sep 19 '18 at 18:51
  • @juharr I'm not sure I understand how to pass in a lambda when invoking the method. Can you add an answer with your description of how to do that? – DannyD Sep 19 '18 at 20:37

0 Answers0