f# - 如何在 .NET Standard 2.0 的 F# 中定义 ref 结构?

标签 f# ref-struct

F# 4.5 was announced ,据说:

The F# feature set is comprised of

  • [...]

  • The ability to produce IsByRefLike structs (examples of such structs: Span<'T>and ReadOnlySpan<'T>).

如何“生产”这些类型?我尝试了 [<IsByRefLike>]属性,但在 .NET Standard 2.0 中找不到。

最佳答案

该属性位于 System.Runtime.CompilerServices

open System.Runtime.CompilerServices

[<Struct; IsByRefLike>]
type Apa =
    { A: Span<int>
      B: int }

Phillip Carter 在 What's new in F# 4.5 中谈到了这一点(大约 21 分钟)。

它适用于 .NET Core 和 .NET Framework,但不适用于 .NET Standard 2.0。

关于f# - 如何在 .NET Standard 2.0 的 F# 中定义 ref 结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53936612/

相关文章:

c# - 为什么 ref 结构不能用作类型参数?

c# - 为什么不能将 `stackalloc` 表达式分配给 `Span<T>` 参数?

f# - 将表达式树解析为嵌套列表

f# - 如何在 VS 2015 中使用 FSharp.Data?

f# - 如何从 F# 中的任务编写 SelectMany

function - F# 中 let、fun 和 function 之间的区别

.net - 现有 ETW 提供程序的 System.Diagnostic.Tracing.EventListener

c# - 如何使用 xUnit 测试 ref struct 方法是否抛出异常?