Why do I get ambiguous call error between (Func<IInterface>) and (Func<Task<IInterface>>) for the next code sample? And how can I avoid this error without replacing method group call?
public class Program
{
public static void Main(string[] args)
{
Method(GetObject);
}
public static IInterface GetObject() => null;
public static void Method(Func<IInterface> func) =>
Console.WriteLine("First");
public static void Method(Func<Task<IInterface>> funcAsync) =>
Console.WriteLine("Second");
}
public interface IInterface { }
This will fix the issue as your method expects a function that returns IInterface
public class Program
{
public static void Main(string[] args)
{
Method(() => GetObject());
}
public static IInterface GetObject() => null;
public static void Method(Func<IInterface> func) =>
Console.WriteLine("First");
public static void Method(Func<Task<IInterface>> funcAsync) =>
Console.WriteLine("Second");
}
public interface IInterface { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With