gpt4 book ai didi

c# - 如何让子类实现接口(interface)?

转载 作者:行者123 更新时间:2023-11-30 20:20:42 26 4
gpt4 key购买 nike

我已经创建了一个类和一个子类。我在父类中也有一个接口(interface)。如何让子类实现接口(interface)?

代码是:

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

最佳答案

这就是您的代码的布局方式。

public interface ISmth
{
void MyMethod();
}

class Car
{
}

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

似乎没有理由将 ISmth 嵌套在 Car 中,但如果你有一个,你当然可以做到。

关于c# - 如何让子类实现接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35663209/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com