Compiler Error CS1940
Multiple implementations of the query pattern were found for source type 'type'. Ambiguous call to 'method'.
This error is generated when multiple implementations of a query method are defined and the compiler cannot disambiguate which one is best to use for the query. In the following example, both versions of Select
have the same signature, because they both accept one int
as an input parameter and have int
as a return value.
To correct this error
- Provide only one implementation for each method.
Example
The following code generates CS1940:
// cs1940.cs
using System; //must include explicitly for types defined in 3.5
class Test
{
public delegate int Dele(int x);
int num = 0;
public int Select(Func<int, int> d)
{
return d(this.num);
}
public int Select(Dele d) // CS1940
{
return d(this.num) + 1;
}
public static void Main()
{
var q = from x in new Test()
select x;
}
}
See also
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for