Make list immutable [duplicate]

2020-04-18 05:36发布

Possible Duplicate:
Immutable List in C#

Is it possible to make a list immutable

标签: c#
2条回答
家丑人穷心不美
2楼-- · 2020-04-18 05:57

List<T>.AsReadOnly() returns a readonly wrapper, so that you can't add/remove/replace elements.

To be truly immutable, the type T must be an immutable Type.

查看更多
The star\"
3楼-- · 2020-04-18 06:01

You can use ReadOnlyCollection<T> instead.

查看更多
登录 后发表回答