为什么在ReadOnlyCollection上使用ImmutableList? [英] Why use ImmutableList over ReadOnlyCollection?
本文介绍了为什么在ReadOnlyCollection上使用ImmutableList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
.NET 4.5具有新的命名空间 System.Collections不可变
.NET 4.5 has a new namespace System.Collections.Immutable
此软件包提供了线程安全的集合,并保证永不更改其内容,也称为不可变集合.
This package provides collections that are thread safe and guaranteed to never change their contents, also known as immutable collections.
我很困惑. ReadOnlyCollection 并不能解决线程安全问题班级?为什么使用 ImmutableList 代替?
I'm confused. Isn't the thread safety problem already solved by the ReadOnlyCollection class? Why use ImmutableList instead?
我知道还有一个 IReadOnlyList 接口 .但这并不能隐式解决线程安全问题,因为其他线程可能会通过另一个接口来编辑对象.
I know there's also an IReadOnlyList interface. That doesn't solve the thread safety problem implicitly, because other threads may edit the object by another interface.
推荐答案
查看全文