是否存在(如果不在标准库中,则可能作为 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/