如何修复vscode中的C#警告CA1416?
我刚刚开始学习《布拉克斯》之后的《C》。在编写过程中,我在vscode中发现了这个问题:如何修复vscode中的C#警告CA1416?,c#,visual-studio-code,C#,Visual Studio Code,我刚刚开始学习《布拉克斯》之后的《C》。在编写过程中,我在vscode中发现了这个问题: { "resource": "/d:/OneDrive/Programming/Youtube/brackeys/How To Program In C#/Basics/Program.cs", "owner": "msCompile", "code": "CA1416", "s
{
"resource": "/d:/OneDrive/Programming/Youtube/brackeys/How To Program In C#/Basics/Program.cs",
"owner": "msCompile",
"code": "CA1416",
"severity": 4,
"message": "This call site is reachable on all platforms. 'Console.WindowHeight.set' is only supported on: 'windows'. [D:\\OneDrive\\Programming\\Youtube\\brackeys\\How To Program In C#\\Basics\\Basics.csproj]",
"startLineNumber": 11,
"startColumn": 13,
"endLineNumber": 11,
"endColumn": 13
}
我发现这是在谈论这个警告,但如果它实际上是:(
我有一个简单的程序,只是学习控制台类更改终端高度和字体颜色等:
using System;
namespace Basics
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Skynet";
Console.ForegroundColor = ConsoleColor.Green;
Console.WindowHeight = 40;
Console.WriteLine();
Console.ReadKey();
}
}
}
有人知道如何解决这个问题吗?所以错误是关于这一行:
Console.WindowHeight=40;
您尝试设置窗口高度,这是一个用[SupportedOSPlatform(“windows”)]
属性修饰的方法
为了告诉应用程序在Windows中仅执行此行,请包装该方法
if(OperatingSystem.IsWindows())
{
控制台高度=40;
}
编译器将识别出这一点并停止抛出注释。哦,现在我明白了!非常感谢您的时间和帮助!您让我很容易正确理解:D.不客气。祝您学习c#愉快。