无法使用 .NET Core 3 预览版 4 编译 C# 8
Unable to compile C# 8 using .NET Core 3, Preview 4
我目前正在使用 .NET Core 3,预览版 4 和 Visual Studio 2019,版本 16.0.2。
这是我的 .NET Core 项目的 .csproj
文件的内容:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
</Project>
作为实验,我从 this page 复制了一些代码到我的项目中:
public static string RockPaperScissors(string first, string second)
=> (first, second) switch
{
("rock", "paper") => "rock is covered by paper. Paper wins.",
("rock", "scissors") => "rock breaks scissors. Rock wins.",
("paper", "rock") => "paper covers rock. Paper wins.",
("paper", "scissors") => "paper is cut by scissors. Scissors wins.",
("scissors", "rock") => "scissors is broken by rock. Rock wins.",
("scissors", "paper") => "scissors cuts paper. Scissors wins.",
(_, _) => "tie"
};
但是,它不会编译:
如您所见,编译器显示错误消息 "Unexpected token"。
我应该怎么做才能在我的 .NET Core 项目中使用 C# 8 语言功能?
我禁用了 ReSharper,问题消失了。
我目前正在使用 .NET Core 3,预览版 4 和 Visual Studio 2019,版本 16.0.2。
这是我的 .NET Core 项目的 .csproj
文件的内容:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
</Project>
作为实验,我从 this page 复制了一些代码到我的项目中:
public static string RockPaperScissors(string first, string second)
=> (first, second) switch
{
("rock", "paper") => "rock is covered by paper. Paper wins.",
("rock", "scissors") => "rock breaks scissors. Rock wins.",
("paper", "rock") => "paper covers rock. Paper wins.",
("paper", "scissors") => "paper is cut by scissors. Scissors wins.",
("scissors", "rock") => "scissors is broken by rock. Rock wins.",
("scissors", "paper") => "scissors cuts paper. Scissors wins.",
(_, _) => "tie"
};
但是,它不会编译:
如您所见,编译器显示错误消息 "Unexpected token"。
我应该怎么做才能在我的 .NET Core 项目中使用 C# 8 语言功能?
我禁用了 ReSharper,问题消失了。