简体   繁体   English

如何在F#中使用Span?

[英]How to use Span in F# interactive?

I try to add reference to System.Memory by 我尝试添加对System.Memory的引用

#r "C:/Program Files/dotnet/shared/Microsoft.NETCore.App/2.1.5/System.Memory.dll"

But F# interactive still says The value or constructor 'Span' is not defined . 但是F#interactive仍然表示The value or constructor 'Span' is not defined And When I try to use open System.Memory it says The namespace 'Memory' is not defined . 当我尝试使用开放的System.Memory它说The namespace 'Memory' is not defined Is there a way to do this? 有没有办法做到这一点?

You don't need to open System.Memory but you do need to open System . 您不需要open System.Memory但需要open System You might also want to nuget System.Memory into a .NET framework application first, and then reference it. 您可能还希望首先将System.Memory编入.NET框架应用程序,然后引用它。 I wonder though how FSI will interact with Span<T> . 我想知道FSI将如何与Span<T>互动。

#if INTERACTIVE
#r @"C:\Users\username\Documents\Source\ConsoleApplication1\packages\System.Memory.4.5.1\lib\netstandard2.0\System.Memory.dll"
#r "System.Runtime.dll"
#endif


open System
open System.Runtime.CompilerServices

[<IsByRefLike; Struct>]
type S(count1: Span<int>, count2: Span<int>) =
    member x.Count1 = count1
    member x.Count2 = count2  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM