static method cannot implement interface method, why?

后端 未结 6 1253
刺人心
刺人心 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:56

    An interface defines the behaviour that an object must respond to. As Foo is a static method, the object doesn't respond to it. In other words, you couldn't write...

    XXX myXXX = new XXX();
    myXXX.Foo();
    

    In other words, myXXX doesn't fully satisfy the requirements of the interface.

提交回复
热议问题