问题描述
我正在寻找.NET副本上写的集合在C#程序,如列表,字典等,要使用的集具有财产?
I am searching for .NET copy-on-write collections to use in C# programs, such as List, Dictionary, etc. Which collections have that property?
推荐答案
包括参考 FSharp.Core
。然后,您可以访问多种集合类是不可变的(设置
,列表
,地图
等。)
Include the reference FSharp.Core
. And then you have access to many kinds of collections which is immutable (Set
, List
, Map
etc.)
这些位于 Microsoft.FSharp.Collections
。
例如:
var map = MapModule.Empty<string, int>();
var newMap = map.Add("key", 1);
您可能要定义一些扩展方法,所以可以直接调用地图
。
You probably want to define some extension methods so you can call directly on map
.
更新:首创置业团队正在不可改变的集合中提到的对方的回答这使得这部分过时。 F#集合仍然可以使用,但BCL集合有多个C#感觉他们
Update: The BCL team is working on immutable collections as mentioned in the other answer which makes this partly obsolete. F# collections can still be used, but BCL collections have a more C# feel to them.
直接链接到的NuGet包:不可变的集合
Direct link to Nuget package: Immutable Collections
这篇关于其中.NET库有复制上写的集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!