static void Main()
// Set up the ReadOnlyCollection.
StringBuilder array = new StringBuilder;
array = new StringBuilder();
var read = new ReadOnlyCollection<StringBuilder>(array);
// Now we change an object pointed to in a ReadOnlyCollection.
A note. Read-only status is not transferred to other references. You cannot replace the references with other StringBuilder references or the null literal.
Summary. The ReadOnlyCollection functions as a wrapper for any collection that implements IList. It adds a level of indirection that reduces possible changes.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Mar 14, 2023 (edit).