Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List and ReadOnly property

List (and List) instances can be readonly, seeing ReadOnly property; methods throws exceptions in the case the collection have the property ReadOnly property.

How can I create readonly List instances? What are the main uses?

like image 334
Luca Avatar asked Feb 27 '23 22:02

Luca


1 Answers

ReadOnlyCollection

From the link above:

"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."

So, anytime you need a collection that is not changeable, use this.

like image 115
Michael Todd Avatar answered Mar 06 '23 11:03

Michael Todd