Reputation: 554
In C#: Is there a way to define the content of a List const/readonly like in C++?
C++ Example:
List<const Content> listWithConstContent;
Upvotes: 2
Views: 656
Reputation: 143
Read-only and immutable are different properties. Which one do you expect?
Upvotes: 1
Reputation: 43254
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>
Upvotes: 1