为什么我们不能指定接口的构造? [英] Why are we not allowed to specify a constructor in an interface?
本文介绍了为什么我们不能指定接口的构造?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/619856/interface-defining-a-constructor-signature">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.
这篇关于为什么我们不能指定接口的构造?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文