How does AsReadOnly return a copy of the collection?

I would like to know if this method returns a copy of the collection or just an instance of ReadOnlyCollection, which somehow wraps the original collection without reading all the links.

I have to understand if he is going to subside memory space, will copy all pointers to my instances?

Thanks for any answer.

+4
source share
2 answers

as you can find here: List (from T). AsReadOnly Method

To prevent any changes to List (Of T), output only List (Of T) through this shell.

A read-only collection is simply a collection with a shell, which prevents the collection from being modified; therefore, if changes are made to the main collection, the read-only collection reflects these changes.

This method is an O (1) operation.

since in the last statement they say that if you change the original collection, the readonly assembly will reflect these changes, I believe that this shell does not reassign any object, but does what you also described in your question.

+6
source

The AsReadOnly method on a List<T> simply returns a ReadOnlyCollection<T> wrapper on top of an existing List<T> . It does not copy the underlying List<T>

+2
source

All Articles