How to

create readonly collection

Published: 14. February 2012 | Updated: 14. February 2012
License: Microsoft Public License (MS-PL)
Categories: Collections
Tags: C# Collections Linq
Was this snippet helpful for you? YESYES / NONO

Import namespaces

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

Code

var items = new List<MyClass>();
// ... fill collection

ReadOnlyCollection<MyClass> collection = items.AsReadOnly();
// or
ReadOnlyCollection<MyClass> collection = new ReadOnlyCollection<MyClass>(items);
Send us feedback about this snippet »



Related Snippets: