C# 纯函数字典

标签 c# .net collections functional-programming

是否存在(如果不在标准库中,则可能作为 Nuget 包)一个类,适合从 C# 使用,提供纯函数字典?也就是说,添加或删除一个键,将返回一个新的字典,同时保持原来的字典不变?

最佳答案

您正在寻找不可变 集合,ImmutableDictionary<TKey, TValue>在你的情况下:

https://msdn.microsoft.com/en-us/library/dn467181(v=vs.111).aspx

When you manipulate an immutable dictionary a copy of the original dictionary is made, manipulations applied and a new immutable dictionary is returned.

关于C# 纯函数字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41869892/

相关文章:

javascript - 过滤 Backbone 集合返回模型数组

.net - NUnit 中在集合上断言相等长度的最惯用的方法

c# - Blazor 组件双向数据绑定(bind)

.net - 检查是否安装了 SQL CE 的最佳方法,如果安装了是什么版本?

.net - 在 .NET 中使用 XmlReader 转义 XML 实体?

c# - 在 .NET 中通过线路移动对象时哪种方法最有效?

c# - 从底层 ObservableCollection 源获取所选 CollectionView 项目的索引

c# - Visual Studio 项目系统遇到错误

c# - 使用 Assembly.GetCallingAssembly() 不返回调用程序集

c# - 使用 yield return 时 GetEnumerator() 方法会发生什么情况?