【发布时间】:2010-03-05 09:15:32
【问题描述】:
C#构造函数extern修饰符的作用是什么?
我知道使用 extern METHODS 来调用 Win32 函数,但是 CONSTRUCTORS 呢?
请举个实际例子。
注意这一点:
class MyClass
{
public extern MyClass();
}
【问题讨论】:
-
请举例说明你的意思。
-
我认为 MSDN 版本的定义和示例会有所帮助吗? msdn.microsoft.com/en-us/library/e59b22c5%28VS.80%29.aspx
-
但这对构造函数不起作用,也许这是他的问题,但我不确定,因此我希望他详细说明。
-
@Lasse:在 C# 规范第 10.11 段实例构造函数中说构造函数可以是外部的:
When a constructor declaration includes an extern modifier, the constructor is said to be an external constructor. Because an external constructor declaration provides no actual implementation, its constructor-body consists of a semicolon. For all other constructors, the constructor-body consists of a block which specifies the statements to initialize a new instance of the class. -
好吧,那我就不知道了。考虑到您实际上无法实现构造函数,我看不出这将如何工作。我怀疑这与在其他地方用IL生成代码有关,无论如何,我删除了我的错误答案。