The following code gives the error:
no best type found for implicitly typed array
But why? All methods have the same signature, so I'd expect the type inference to succeed.
- Notes:
- I'm using .NET Framework 4.7.2.
- I'm aware I can use an explicit array declaration, but I'm interested in understanding the reason for the error.
Code (live demo):
public class Program
{
public static void Main()
{
var validators = new[] { Validator1, Validator2 }; // <-- error
Validate(validators);
}
public static bool Validator1(string s)
{
return true;
}
public static bool Validator2(string s)
{
return true;
}
public static bool Validate(Func<string, bool>[] funcs)
{
return true;
}
}