Collection

S

Stoitcho Goutsev \(100\) [C# MVP]

Hi wansch,

I don't know what do you mean by 'external users', but ArrayList has static
method ReadOnly that returns readonly wrapper around the array lists or
objects that expose IList interface.

If you want strongly type collections you can inherit form
ReadOnlyCollectionBase and create your own. You may have for example
internal methods for modifying the collections and public methods for
accessing elements in a readonly manner.
 
G

Guest

I don't think you can, quite.

As a work-around, create your own class that implements IList, contains a
private collection, and which for the readonly Item() property, returns not
an element from the collection, but a clone of it.

That way, at least any changes made will be changes to the (discarded)
clone, and not to the actual elements in the collection.
 
G

Guest

I don't think you can, quite.

As a work-around, create your own class that implements IList, contains a
private collection, and which for the readonly Item() property, returns not
an element from the collection, but a clone of it.

That way, at least any changes made will be changes to the (discarded)
clone, and not to the actual elements in the collection.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top