Alex Rivera | Logout

How to Convert List<string> to ReadOnlyCollection<string> in C#

Asked 2011-11-15T17:16:07.667
58

I want to convert the items entered to a String list to:

System.Collections.ObjectModel.ReadOnlyCollection<string>

I have tried using:

(System.Collections.ObjectModel.ReadOnlyCollection<string>)listname

But it returns an error.

Edit
Report

1 Answer

6

The constructor of ReadOnlyCollection accepts an IList

Here is some reference http://msdn.microsoft.com/en-us/library/ms132476.aspx

var myreadonlycollection = new ReadOnlyCollection<string>(listname);
answered 2011-11-15T17:18:36.447

Your Answer