接口只包含方法委托事件的签名。方法的实现是在实现接口的类中完成的,如下面的示例所示:

 CopyCode image复制代码
        interface ISampleInterface
{
    void SampleMethod();
}

class ImplementationClass : ISampleInterface
{
    // Explicit interface member implementation: 
    void ISampleInterface.SampleMethod()
    {
        // Method implementation.
    }

    static void Main()
    {
        // Declare an interface instance.
        ISampleInterface obj = new ImplementationClass();

        // Call the member.
        obj.SampleMethod();
    }
}

Expand 图像备注

Expand 图像示例

Expand 图像C# 语言规范

Expand image请参见