C#: Immutable view of a list's objects?

Posted by Rosarch on Stack Overflow See other posts from Stack Overflow or by Rosarch
Published on 2010-04-15T23:17:48Z Indexed on 2010/04/15 23:23 UTC
Read the original article Hit count: 214

Filed under:
|

I have a list, and I want to provide read-only access to a collection containing its contents. How can I do this?

Something like:

public ICollection<Foo> ImmutableViewOfInventory() {

    IList<Foo> inventory = new List<Foo>();

    inventory.add(new Foo());

    return inventory.ImmutableView();

}

Additionally, an immutable IEnumerable would also be fine.

© Stack Overflow or respective owner

Related posts about c#

Related posts about immutable