无法访问静态属性/字段(C#)
我得到一个编译时异常,它声明:无法访问静态属性/字段(C#),c#,static-members,C#,Static Members,我得到一个编译时异常,它声明: Actor.TimeScale.get' cannot be accessed with an instance reference; qualify it with a type name instead. 这是代码,已清理为仅相关行: class Actor { static float _timeScale = 1.0f; public static float TimeScale { get { ret
Actor.TimeScale.get' cannot be accessed with an instance reference;
qualify it with a type name instead.
这是代码,已清理为仅相关行:
class Actor
{
static float _timeScale = 1.0f;
public static float TimeScale
{
get { return _timeScale; }
set { _timeScale = value; }
}
}
class Game1
{
private void BeginLevel()
{
Actor.TimeScale = 0.3f;
}
}
现在,我知道static有点问题,但我不明白是什么。一个儿童级的演员有:
this.TimeScale;
当然,这对static不太好。你有没有可能在
Game1
中有一个名为Actor
的属性?代码对我来说很好。你能发布一个复制这个错误的完整代码示例吗?你有没有Game1
中的Actor
成员?我想我最后不得不上传整个解决方案。Actor有130行,game1有400行,但可以扩展到许多其他类。@sdiguana:如果替换Actor.TimeScale=0.3f代码>与全局::Your.Actor.Namespace.Actor.TimeScale=0.3f代码>错误是否消失?(请确保将“Your.Actor.Namespace”替换为Actor
所在的命名空间)^用户错误,未充分注意调试窗口指向的类。(脸掌)