In essence, this is a problem with overload resolution.
Count
has only one overload, which takes two arguments (extended argument + predicate), but Where
has two (one where the predicate considers the index of the element, and one that does not). To complicate matters, Regex.IsMatch
has several overloads. Now it turns out that the compiler is right to complain about the ambiguity, since two of these IsMatch
overloads IsMatch
really applicable (each of them is compatible with the other Where
overload):
// Where overload without item-index Regex.IsMatch(string) is compatible with Where<string>(string, Func<string, bool>) // Where overload with item-index Regex.IsMatch(string, int) is compatible with Where<string>(string, Func<string, int, bool>)
... but there may be other related cases related to groups of methods (when return type analysis is required) where the compiler may complain about ambiguity, even if there is no ambiguity for a person .
source share