预定义类型 System.Range 未定义或未导入
predefined type System.Range is not defined or imported
我在 Visual Studio 2019 v16.0.2 的 UWP 应用中使用 C# 8.0(测试版)。
我试图使用 C# 8 的新范围运算符:str[start..index]
然后出现两个错误:
Predefined type System.Range
is not defined or imported
Predefined type System.Index
is not defined or imported
但是没有我可以使用的参考。
Visual Studio 本身建议我使用此功能。是该功能尚未可用还是什么?
这是 .NET Core 3 的一部分,尚未发布。
索引和范围是 C# 8.0 的一部分,它于 2019 年 9 月与 .NET Core 3.0 一起发布。要使用 C# 8.0 的所有功能,您的目标框架必须是以下之一:
- .NET 标准 2.1
- .NET Core 3.0 及更高版本
- .NET 5.0 及更高版本
也可以在早期版本的 .NET 上使用 C# 8.0 功能,例如 .NET Standard 2.0 和 .NET Framework。为此,您需要 override the default C# version on your project. However, Indices and Ranges is not officially supported on these earlier versions and will not work out-of-the-box. That being said, there is a possible workaround to make it work: https://www.meziantou.net/how-to-use-csharp-8-indices-and-ranges-in-dotnet-standard-2-0-and-dotn.htm
我在 Visual Studio 2019 v16.0.2 的 UWP 应用中使用 C# 8.0(测试版)。
我试图使用 C# 8 的新范围运算符:str[start..index]
然后出现两个错误:
Predefined type
System.Range
is not defined or imported
Predefined type
System.Index
is not defined or imported
但是没有我可以使用的参考。
Visual Studio 本身建议我使用此功能。是该功能尚未可用还是什么?
这是 .NET Core 3 的一部分,尚未发布。
索引和范围是 C# 8.0 的一部分,它于 2019 年 9 月与 .NET Core 3.0 一起发布。要使用 C# 8.0 的所有功能,您的目标框架必须是以下之一:
- .NET 标准 2.1
- .NET Core 3.0 及更高版本
- .NET 5.0 及更高版本
也可以在早期版本的 .NET 上使用 C# 8.0 功能,例如 .NET Standard 2.0 和 .NET Framework。为此,您需要 override the default C# version on your project. However, Indices and Ranges is not officially supported on these earlier versions and will not work out-of-the-box. That being said, there is a possible workaround to make it work: https://www.meziantou.net/how-to-use-csharp-8-indices-and-ranges-in-dotnet-standard-2-0-and-dotn.htm