我认为我没有正确理解静态构造函数,因为我得到了DutLog
的错误"Method must have a return type",但它是一个静态构造函数,因此不应该有返回类型?
static public class DutLog
{
static public String m_var1;
static Dutlog()
{
Console.WriteLine("DutLog() - constructor");
m_var1 = "hello";
}
}
您有一个打字错误。类名为DutLog
,而构造函数名为Dutlog
(注意小写l
),因此后者被视为一个方法。