I have an ICollection
called foos
in my class which I want to expose as read-only (see this question). I see that the interface defines a
You can make "foos" a ReadOnlyCollection like this:
ReadOnlyCollection readOnlyCollection = foos.ToList().AsReadOnly();
Then you can expose it as a property of your class.
EDIT:
class FooContainer
{
private ICollection foos;
public ReadOnlyCollection ReadOnlyFoos { get { return foos.ToList().AsReadOnly();} }
}
Note: You should remember that once you get the ReadOnlyFoos collection is no longer "synchronized" with your foos ICollection. See the thread you referenced.