不可变的集合?

由网友(烂泥)分享简介:我提出了我的大部分基本类型在我的应用程序,一成不变的。但应该集合是不可变的吗?对我来说,这似乎是一个巨大的开销,除非我失去了一些东西。I am making most of my basic types in my app, immutable. But should the collections be immut...

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

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:

阅读全文

相关推荐

最新文章