List(和 List)实例可以是只读的,参见 ReadOnly 属性;在集合具有 ReadOnly 属性的情况下,方法会抛出异常。
如何创建只读列表实例?主要用途是什么?
最佳答案
来自上面的链接:
"A collection that is read-only is simply a collection with a wrapper that prevents modifying the collection; therefore, if changes are made to the underlying collection, the read-only collection reflects those changes."
因此,无论何时您需要一个不可更改的集合,都可以使用它。
关于c# - 列表和只读属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2924646/