跨度<T>和溪流 [英] span<T> and streams

查看:20
本文介绍了跨度<T>和溪流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一段时间关于 span 的内容,并试图实现它.但是,虽然我可以让 span 工作,但我无法弄清楚如何像示例中那样让流接受它.其他示例也显示 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

请为我指明正确的方向来完成这项工作.

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 结果.如果您检查当前的源代码,例如 Stream 你会看到它有像 Read(Span) 读入 Span 而不是 byte[],或 Write(ReadOnlySpan) 可以写出 ReadOnlySpan 而不是 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 Preview 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

这篇关于跨度&lt;T&gt;和溪流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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