【问题标题】:CS1022 but there are no missing bracketsCS1022 但没有缺少括号
【发布时间】:2020-06-20 16:58:11
【问题描述】:

Visual Studio 一直很烦人,并且由于某种原因无法识别匹配的括号。只有在括号中键入 2 行后才会出现问题,当它们为空时,一切都很好。我有最新的更新并检查以确保我没有任何奇怪的缩进设置。代码如下:

public class Control : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        public static int gamesPlayed = 0;
        public static int weeks = 0;
        public static int difficulty = 0;
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

【问题讨论】:

    标签: c# visual-studio unity3d


    【解决方案1】:

    您不能在方法中声明字段inside,这就是您在Start 中使用gamesPlayed 等所做的。您需要将它们移出,以便它们处于班级级别:

    public static int gamesPlayed = 0;
    public static int weeks = 0;
    public static int difficulty = 0; 
    void Start() { 
    
    } 
    

    【讨论】:

      【解决方案2】:

      您不能在方法中声明公共或静态变量。这就是为什么它认为缺少括号。方法中声明的任何东西都只用于方法

      将它们移出开始

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-03-31
        • 2016-08-16
        • 2018-04-10
        • 1970-01-01
        • 2021-03-12
        相关资源
        最近更新 更多