【问题标题】:Error CS0305 Using the generic type 'Memory' requires 1 type arguments错误 CS0305 使用泛型类型“内存”需要 1 个类型参数
【发布时间】:2023-03-03 03:35:01
【问题描述】:

我有以下 sn-p 代码来测试/使用 vs 2017 中的 dotnet 2.1,以便尝试和运行 C# 7.2s Span 功能。 在哪里可以找到允许我在 Visual Studio 中运行它的 SDK。 我只能找到最高 2.0 的框架。

using System;
using System.Memory;

namespace sim
{
class Program
{
    static void Main(string[] args)
    {

       var arr = new byte[10];
        Span<byte> bytes = arr; // Implicit cast from T[] to Span<T>

        Span<byte> slicedBytes = bytes.Slice(start: 5, length: 2);

    }      
}
}

否则我将无法运行和使用 错误 CS0305 使用泛型类型“内存”需要 1 个类型参数 sim

【问题讨论】:

标签: c# visual-studio-2017 .net-core c#-7.2


【解决方案1】:

您无需安装任何 SDK 即可使用Span&lt;T&gt;

您需要安装System.Memory nuget 包,这是prerelase 版本。

你可以使用这个命令

Install-Package System.Memory -Version 4.5.0-preview2-26406-04    

您还需要在项目属性中将语言版本设置为7.2,并且您还需要 Visual Studio 15.5 或更高版本

【讨论】:

    【解决方案2】:

    你试过了吗? .NET Core SDK 2.1.4

    【讨论】:

    • 我已经安装了这个,它不会在项目菜单的 TargetFramework 部分创建 .Net Core 2.1 选项
    猜你喜欢
    • 2021-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多