4

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?

Luca
  • 11,646
  • 11
  • 70
  • 125

1 Answers1

8

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.

Michael Todd
  • 16,679
  • 4
  • 49
  • 69
  • Best way to understand this is to read the dinosaur list example from the link provided by Michael. – DanielV Jul 08 '15 at 08:49