I have come across this several times in the last week, and am curious to know the reason - I had a google, but couldn't find anything directly relevant.
I have a class with a dynamic method, and I can add a static method with the same interface:
public class MyClass
{
public int MyMethod()
{
//do something #1;
}
public static int MyMethod()
{
//do something
}
}
This is fine, but if I try to call the static method from the dynamic method, replacing #1 with return MyClass.MyMethod()
, I get an error "The call is ambiguous between the following methods or properties: MyClass.MyMethod() and MyClass.MyMethod().
If the static method is deleted, the error changes to "An object reference is required..", which makes sense.
So why is this ambiguous? It has been prefaced with the class name to specify the static method, which works from anywhere else in code.
Why not here?
EDIT: I hadn't actually tried to compile it without the dynamic method calling the static one, I had just gone by VS not underlining it.
But still a similar question I suppose but with an added "Why can't there be both, as one is static, and one not"