小编Dav*_*cht的帖子

.NET中的不可变集

.NET BCL是否具有不可变的Set类型?我正在编写一个C#的功能方言,并希望做类似的事情

new Set.UnionWith(A).UnionWith(B).UnionWith(C)
Run Code Online (Sandbox Code Playgroud)

但我能找到的最好的是HashSet.UnionWith,这将需要以下一系列调用:

HashSet composite = new HashSet();
composite.UnionWith(A);
composite.UnionWith(B);
composite.UnionWith(C);
Run Code Online (Sandbox Code Playgroud)

这种用途高度参考不透明,使其难以优化和理解.如果没有编写自定义功能集类型,有没有更好的方法呢?

c# functional-programming set immutability

6
推荐指数
2
解决办法
6240
查看次数

标签 统计

c# ×1

functional-programming ×1

immutability ×1

set ×1