错误 CS0305 使用泛型类型“内存"需要 1 个类型参数 [英] Error CS0305 Using the generic type 'Memory' requires 1 type arguments

查看:50
本文介绍了错误 CS0305 使用泛型类型“内存"需要 1 个类型参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the below snippet of code to test/use dotnet 2.1 in vs 2017 in order to try out and run C# 7.2s Span functionality. Where can I find the SDK that allows me to run this within Visual Studio. I can only find frameworks up to 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

Otherwise I'm left unable to run and use Error CS0305 Using the generic type 'Memory' requires 1 type arguments sim

推荐答案

使用Span

您需要安装 System.Memory nuget 包,这是预发布版本.

You need to install System.Memory nuget package which is prerelase version.

你可以使用这个命令

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

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

You also need to set your language version to 7.2 in your project properties and also you need Visual Studio 15.5 or more

这篇关于错误 CS0305 使用泛型类型“内存"需要 1 个类型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆