Reputation: 887449
I'm making an immutable struct in .Net which contains a read only collection of a different immutable struct (I have full control over the entire design). I don't need a non-mutating Add method.
What's the best way to do that?
I could make the outer struct have a reference to a ReadOnlyCollection
containing the inner struct. Are there any other options?
Upvotes: 0
Views: 248
Reputation: 71866
ReadOnlyCollection
is one way.
Depending on what you need to do with the collection, you could also expose it as IEnumerable
instead.
Upvotes: 3