【发布时间】:2013-07-10 00:34:06
【问题描述】:
以下 C# 代码无法编译。
public class BaseType
{
public BaseType(int bar)
{
// Do stuff with bar...
}
}
public class DerivedType : BaseType
{
private int foo;
public DerivedType() : base(foo = 0) {}
}
在调用 DerivedType 的基本构造函数时发生错误,并显示消息“无法在静态上下文中访问非静态字段 'foo'”。这个错误信息告诉我什么? 'foo' 不是静态的,类也不是,它们也不是静态构造函数。
【问题讨论】:
-
我不认为它完全重复,但这是一个非常有用的链接,谢谢@mikez。
标签: c# compiler-errors