In C#: Is there a way to define the content of a List const/readonly like in C++?
C++ Example:
List<const Content> listWithConstContent;
The List<T>
class in the .NET framework is mutable. There is no equivalent of that C++ feature either in C#, or the CLR.
If you want an immutable list, then you need to use eg ImmutableList<T>
Read-only and immutable are different properties. Which one do you expect?
C#不支持那样的不变性
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.