2016-02-26 60 views
0

我已经创建了一个类和一个子类,并且都有一堆代码。我创建了一个父类的接口,我不知道如何让我的子类实现的接口:/如何使一个子类实现一个接口?

的代码是:

class Car { 
       public interface ISmth 
       { 
        void MyMethod(); 
       } 
      } 
class MyCar : Car { 
         //implement the interface 
        } 

回答

0

这就是你的代码应该如何布局。

public interface ISmth 
{ 
    void MyMethod(); 
} 

class Car 
{ 
} 

class MyCar : Car, ISmth 
{ 
    public void MyMethod() 
    { 
    } 
} 

似乎有不是一个理由窝ISmthCar,但如果你有一个你肯定可以做到这一点。

1

需要声明MyCar这样的:

class MyCar: Car, Car.ISmth {} 
相关问题