为什么我们不能指定接口的构造?接口

2023-09-02 11:52:26 作者:追逐我的明天。

可能重复:   Interface定义一个构造函数签名?

我知道,你不能在.NET中的接口指定一个构造函数,但为什么我们不能?

I know that you cannot specify a constructor in an interface in .Net, but why can we not?

这将是非常有益的我当前的项目,以便能够指定一个引擎必须通过在构造函数中,但我不能,我一定要足够用在类的XML注释。

It would be really useful for my current project to be able to specify that an 'engine' must be passed in with the constructor, but as I cant, I have to suffice with an XML comment on the class.

推荐答案

由于接口描述的行为。构造函数不是行为。对象是如何建立是一个实现细节。

Because an interface describes behaviour. Constructors aren't behaviour. How an object is built is an implementation detail.

 
精彩推荐
图片推荐