Ambiguous call between (Func <IInterface>) and (Func <Task <IInterface>>)
Why am I getting an ambiguous call error between (Func<IInterface>)
and (Func<Task<IInterface>>)
for the following code example? And how can I avoid this error without replacing the group method 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 { }
+3
source to share
1 answer
This will fix the problem 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 { }
+1
source to share