ImmutableArray 在哪里?
Where is ImmutableArray?
为什么 ImmutableArray seem to not be there in Microsoft Immutable Collections NuGet package version 1.0.34?
public static class ImmutableArray
ImmutableArray
是static,所以不能实例化。使用:
ImmutableArray.Create<T>(); // Creates an empty immutable array
ImmutableArray
不在您的库版本中。
如您在 version history 中所见,1.1.20 的发行说明提到 "Re-included ImmutableArray<T>"
您可以在这个 announcement 中找到 .NET 博客上 1.0 版本中缺少 ImmutableArray 的原因的解释。 (简而言之,当 Roslyn 团队尝试使用该类型而不是常规数组时,他们的性能受到了明显的影响,负责该库的团队不确定如何解决这个问题,同时保持合理的 API。 )
您将在其新的 NuGet 包下找到该库的更新版本,System.Collections.Immutable
。
N.B.: 根据 System.Collections.Immutable
新版本中的 source code,他们显然已经决定采取 API 命中 - 即一些操作在单元化的 ImmutableArray
上会抛出令人惊讶的 NullReferenceException
s。显然,ImmutableArray
应该 永远不会 用 new
实例化。 (应该改用ImmutableArray<T>.Empty
)
为什么 ImmutableArray seem to not be there in Microsoft Immutable Collections NuGet package version 1.0.34?
public static class ImmutableArray
ImmutableArray
是static,所以不能实例化。使用:
ImmutableArray.Create<T>(); // Creates an empty immutable array
ImmutableArray
不在您的库版本中。
如您在 version history 中所见,1.1.20 的发行说明提到 "Re-included ImmutableArray<T>"
您可以在这个 announcement 中找到 .NET 博客上 1.0 版本中缺少 ImmutableArray 的原因的解释。 (简而言之,当 Roslyn 团队尝试使用该类型而不是常规数组时,他们的性能受到了明显的影响,负责该库的团队不确定如何解决这个问题,同时保持合理的 API。 )
您将在其新的 NuGet 包下找到该库的更新版本,System.Collections.Immutable
。
N.B.: 根据 System.Collections.Immutable
新版本中的 source code,他们显然已经决定采取 API 命中 - 即一些操作在单元化的 ImmutableArray
上会抛出令人惊讶的 NullReferenceException
s。显然,ImmutableArray
应该 永远不会 用 new
实例化。 (应该改用ImmutableArray<T>.Empty
)