在 Win10 上使用 csc.exe
编译时,清除此错误时遇到一些问题。我对 C# 很陌生。在我 1 月份开始上课之前做一些自学。
遵循有关执行此操作的“TeamTreehouse”教程。他们在工作区中使用 mono
。我更喜欢在我的机器上使用 vscode
来熟悉在单声道之外使用 C#。
从我读到的关于 CS0501 的内容来看,我的问题是编译器问题,不应该是问题,但使用 csc.exe
会导致问题。添加 abstract
会带来一系列全新的问题。
从终端编译器使用的命令是csc *.cs
我不确定下一步该去哪里寻找解决方案。我一直无法使用所谓的 Auto-Implemented Properties
找到一个可用的。
错误是
Invader.cs(6,39): error CS0501: 'TreehouseDefense.Invader.Location.get' must declare a body because it is not marked abstract or extern
Invader.cs(6,52): error CS0501: 'TreehouseDefense.Invader.Location.set' must declare a body because it is not marked abstract or extern
代码 入侵者.cs
namespace TreehouseDefense {
class Invader {
public MapLocation Location { get; private set; }
}
}
项目 对象_项目.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
</Project>
最佳答案
您使用的是 2005 年的 C# 2 编译器。C# 2 不支持自动实现的属性 - 以及作为现代 C# 一部分的各种其他功能。
您想运行 C# 7 编译器。我建议安装 Visual Studio 2017 Community Edition ,并使用 Visual Studio 2017 命令提示符,以便路径上有正确版本的 csc
。
或者只下载.NET Core SDK并使用 dotnet
命令来构建和运行而不是 csc
。
关于c# - 错误 : must declare a body because it is not marked abstract or extern,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53836091/