首页 > 解决方案 > Visual Studio Code 在 C# 中不会出现范围错误

问题描述

我正在使用 VS Code 在 C# 中学习和测试范围。但令我惊讶的是,VS Code 没有出现关于变量“消息”不在所需范围内的警告/错误。这是文件:

using System;

    public class TestScope
    {
        public static void Main()
        {
            int score = 100;

            if (score >= 50)
                string message = "Good score";  // Declared in if statement

            Console.WriteLine(message);         // Variable unavailable
        }
    }

我安装了 Microsoft 的扩展 C# v1.17.1,文件被 VS Code 正确识别。我徘徊是我错过了一些扩展还是没有正确设置。有什么帮助吗?

标签: c#visual-studio-code

解决方案


推荐阅读