不可变的集合? [英] Immutable collections?

查看:134
本文介绍了不可变的集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提出了我的大部分基本类型在我的应用程序,一成不变的。但应该集合是不可变的吗?对我来说,这似乎是一个巨大的开销,除非我失去了一些东西。

I am making most of my basic types in my app, immutable. But should the collections be immutable too? To me, this seems like a huge overhead unless I am missing something.

我说的藏品持有POINT3值等可以添加,因为它不用在不同的时间。因此,如果有一个集合1M值,你需要删除1人,你将不得不从头再来创建相同的集合,对吧?

I am talking about collections to hold Point3 values, etc which can be added as it goes at different times. So if there are 1M values in a collection, and you needed to delete 1 of them, you would have to create the same collection all over again, right?

推荐答案

埃里克利珀有系列对不变性在C#的,如果你读这一切通过他实现了几个不同的不可变的集合的方式:

Eric Lippert has a series on Immutability in C#, and if you read it all the way through he implements a couple different immutable collections:

这篇关于不可变的集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆