Collection wrapping a array is read-only. Possible to make it writeable without casting?
- by Brian Triplett
I have a Collection<T> property that wraps a array like
T[] array;
public Collection<T> Items
{
get { return new Collection<T>(array); }
}
When I attempt to assign to the collection via:
T variable;
Items[i] = variable;
I get a NotSupportedException because the colleciton's IsReadOnly property is true. Turns out that this is a design choice by Microsoft. Does anyone know a workaround that does NOT involve enumeration? It could be done if the underlying data is not an array but I enjoy the performance gains because the data is fixed length.