C# Compiler Errors and Warn ...


Visual C# Reference: Errors and Warnings
Compiler Warning (level 2) CS0467

Error Message

Ambiguity between method 'method' and non-method 'non-method'. Using method group.

Inherited members with same signature, from different interfaces, cause ambiguity error.

Example

The following example generates CS0467.

// CS0467.cs
interface IList 
{
int Count { get; set; }
}
interface ICounter
{
void Count(int i);
}

interface IListCounter : IList, ICounter {}

class Driver 
{
    void Test(IListCounter x)
    {
        x.Count = 1;
        x.Count(1);   // CS0467
        // To resolve change the method name "Count" to another name.
    }
    
    static void Main() 
    {
    }
}
See Also

Tasks

Tags :


Community Content

JoeBuddha
LAME
This is the LAMEST warning ever. If I'm using a name as a METHOD, why would there be any ambiguity? Var figures out what you want from context, after all.
Tags :

CSTeam
definitely.
Yeah it's great that you can resolve the error by changing method names, but what if you didn't write the class? right now I'm working with the

Microsoft.Office.Interop.Word close method and there's no way to rewrite it.

ANSWER:
You can create an object of a necessary interface. For example, this is how you can resolve this error without changing the method name:

void Test(IListCounter x)

{

IList list = x;

list.Count = 1;


ICounter counter = x;

counter.Count(1);

}

Tags : contentbug

Page view tracker