Static and Instance methods with the same name?

I have a class with both a static and a non-static interface in C#. Is it possible to have a static and a non-static method in a class with the same name and signature?

I get a compiler error when I try to do this, but for some reason I thought there was a way to do this. Am I wrong or is there no way to have both static and non-static methods in the same class?

If this is not possible, is there a good way to implement something like this that can be applied generically to any situation?

EDIT
From the responses I've received, it's clear that there is no way to do this. I'm going with a different naming system to work around this problem.


Solution 1:

No you can't. The reason for the limitation is that static methods can also be called from non-static contexts without needing to prepend the class name (so MyStaticMethod() instead of MyClass.MyStaticMethod()). The compiler can't tell which you're looking for if you have both.

You can have static and non-static methods with the same name, but different parameters following the same rules as method overloading, they just can't have exactly the same signature.

Solution 2:

Actually, there kind of is a way to accomplish this by explicitly implementing an interface. It is not a perfect solution but it can work in some cases.

interface IFoo
{
    void Bar();
}

class Foo : IFoo
{
    static void Bar()
    {
    }

    void IFoo.Bar()
    {
        Bar();
    }
}

I sometimes run into this situation when I make wrapper classes for P/Invoke calls.