[英]How to create a C# List with const content?
In C#: Is there a way to define the content of a List const/readonly like in C++? 在C#中:是否可以像在C ++中那样定义List const / readonly的内容?
C++ Example: C ++示例:
List<const Content> listWithConstContent;
The List<T>
class in the .NET framework is mutable. .NET框架中的
List<T>
类是可变的。 There is no equivalent of that C++ feature either in C#, or the CLR. C#或CLR中都没有等效的C ++功能。
If you want an immutable list, then you need to use eg ImmutableList<T>
如果您想要一个不可变列表,则需要使用例如
ImmutableList<T>
Read-only and immutable are different properties. 只读和不可变是不同的属性。 Which one do you expect?
您期望哪一个?
C#不支持那样的不变性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.