In would like to know if this method returns a copy of the collection or just an instance of ReadOnlyCollection which will wrap the original collection in some way, without readding all references.
I must understand if it's going to waste memory space, will it copy all pointers to my instances?
Thanks for any answer.
as you can find here: List(Of T).AsReadOnly Method
To prevent any modifications to List(Of T), expose List(Of T) only through this wrapper.
A collection that is read-only is simply a collection with a wrapper that prevents modifying the collection; therefore, if changes are made to the underlying collection, the read-only collection reflects those changes.
This method is an O(1) operation.
since in the last statement they say if you change the source collection the readonly collection will reflect those changes, I believe this wrapper does not re-allocate any object but does what you also described in your question.
The AsReadOnly
method on List<T>
just returns a ReadOnlyCollection<T>
wrapper over the existing List<T>
. It doesn't copy the underlying List<T>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With