不可变的集合?

编程入门 行业动态 更新时间:2024-10-24 02:28:57
本文介绍了不可变的集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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:

更多推荐

不可变的集合?

本文发布于:2023-10-19 14:51:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1507848.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!