SLaks
SLaks

Reputation: 887449

Immutable struct with collection

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

Answers (1)

Cameron MacFarland
Cameron MacFarland

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

Related Questions