static method cannot implement interface method, why?

后端 未结 6 1273
刺人心
刺人心 2021-02-20 04:24
interface IXXX
{
    void Foo();
}

class XXX : IXXX
{
    public static void Foo()
    {
        Console.WriteLine(\"From XXX\");
    }
}


class Program 
{
    static          


        
6条回答
  •  春和景丽
    2021-02-20 04:37

    See this thread from JoelOnSoftware describing the reasons behind this.

    Basically the interface is the contract between the consumer and the provider, and a static method belongs to the class, and not each instance of the class as such.

    An earlier question on SO also deal with the exact same question: Why Doesn't C# Allow Static Methods to Implement an Interface?

提交回复
热议问题