简体   繁体   English

CS1525 - 无效的表达式术语 '^'

[英]CS1525 - Invalid expression term '^'

I'm trying to get the console to print the last word in the following string array and added the code below:我试图让控制台打印以下字符串数组中的最后一个单词并添加以下代码:

static void Main(string[] args)
{
    string[] words = new string[]
    {
        "Richard",
        "Of",
        "York",
        "Gave",
        "Battle",
        "In",
        "Vain"
    };

    Console.WriteLine($"The last word is {words[^1]}");

}

The compiler throws the error编译器抛出错误

Invalid expression term '^' for the '^' operator. '^' 运算符的表达式项 '^' 无效。

Any help will be much appreciated.任何帮助都感激不尽。

Install latest.Net SDK for your platform and/or update Visual Studio Download .NET SDKs为您的平台安装 latest.Net SDK 和/或更新 Visual Studio下载 .NET SDK

Make sure to have the latest .NET Core SDK installed, and also check the settings of your project.确保安装了最新的 .NET Core SDK,并检查项目的设置。

  • If it's a class library, chances are that it'll be a .NET Standard library.如果它是一个 class 库,那么它很可能是一个 .NET 标准库。 Make sure to have a .NET Standard 2.1 version specified in your project.确保在您的项目中指定了 .NET 标准 2.1 版本。
  • If it's another type, you should have a .NET Core project.如果是另一种类型,您应该有一个 .NET Core 项目。 Make sure that it's 3.0+确保它是 3.0+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM