Error CS0305 Using the generic type 'Memory' requires 1 type arguments

雨燕双飞 提交于 2019-12-11 18:17:03

问题


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);

    }      
}
}

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


回答1:


You do not need to install any SDK for using Span<T>

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

you can use this command

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

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




回答2:


Have you tried this? .NET Core SDK 2.1.4



来源:https://stackoverflow.com/questions/49916183/error-cs0305-using-the-generic-type-memory-requires-1-type-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!