无法访问静态属性/字段(C#)

时间:2014-03-14 15:14:07

标签: 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 { return _timeScale; }
        set { _timeScale = value; }
    }
}
class Game1
{
    private void BeginLevel()
    {
        Actor.TimeScale = 0.3f;
    }
}

现在,我知道静态有些不妥,但我不明白。

1 个答案:

答案 0 :(得分:0)

演员的儿童班有:

this.TimeScale;

当然,静态无效。