Does a Collection<T> wrap an IList<T> or enumerate over the IList<T>?
- by Brian Triplett
If I am exposing a internal member via a Collection property via:
public Collection<T> Entries
{
get { return new Collection<T>(this.fieldImplimentingIList<T>); }
}
When this property is called what happens? For example what happens when the following lines of code are called:
T test = instanceOfAbove.Entries[i];
instanceOfAbove[i] = valueOfTypeT;
It's clear that each time this property is called a new reference type is created but what acctually happens? Does it simply wrap the IList<T> underneath, does it enumerate over the IList<T> and to create a new Collection<T> instance? I'm concerned about performance if this property is used in a for loop.