跨度T和流 [英] span<T> and streams
问题描述
我已经读了一段时间了,只是尝试实现它。但是,尽管我可以跨度工作,但是我无法弄清楚如何像示例中那样使流接受它。其他示例也显示了int.parse支持范围,但我找不到使之成为可能的重载或扩展。
I have been reading about span for a while now, and just tried to implement it. However, while I can get span to work I cannot figure out how to get a stream to accept it like they do in the examples. Other examples show int.parse supporting spans as well but I can't find overloads or extensions that make it possible.
我在.net Standard 2.0和.net core 2.0中都尝试过。
I have tried it in both .net Standard 2.0 and .net core 2.0.
请为我指出正确的方向,以使其正常工作。
Please point me in the right direction to make this work.
编辑:代码示例为:
Span<Byte> buffer = new Span<byte>();
int bytesRead = stream.Read(buffer);
推荐答案
.NET Core 2.1支持流的跨度结果。如果您查看当前的源代码,例如流,您会看到它具有读取(跨度),它读取到 Span< byte>
而不是 byte []
或写(ReadOnlySpan)可以写出 ReadOnlySpan< byte>
而不是 byte []
,使用内存的重载等。
Span results from streams are supported in .NET Core 2.1. If you check the current source code of eg Stream you'll see it has overloads like Read(Span) that read into a Span<byte>
instead of byte[]
, or Write(ReadOnlySpan) that can write out a ReadOnlySpan<byte>
instead of a byte[]
, overloads that use Memory etc.
要定位.NET Core 2.1,必须至少安装 Visual Studio 2017 15.7预览版4 或。NET Core 2.1的最新SDK
To target .NET Core 2.1, you'll have to install at least Visual Studio 2017 15.7 Preview 4 or the latest SDK for .NET Core 2.1
这篇关于跨度T和流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!