Kun*_*esh 5 c# constructor destructor interface
我知道界面正在运行.当我开始编写项目编码时,我心中就怀疑了.任何人都可以澄清吗?
据我了解,您想知道为什么我们不能指定构造函数的签名以及其他对象的方法,例如
interface IApp
{
void App(int i, int j);
}
class App : IApp
{
// You want constructor to be only with 2 parameters
public void App(int i, int j){ }
}
Run Code Online (Sandbox Code Playgroud)
这是不可能的,因为首先,所有接口方法都应该实现为 public,但构造函数可以设置为 private,其次,方法void App(..)将仅作为类 App 的构造函数,对于另一个类,它会是另一种方法。
因此,通常,如果您想指定具有已知参数的构造函数,请尝试使用抽象基类。