Skip to content

Instantly share code, notes, and snippets.

@shiftkey
Created April 19, 2011 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiftkey/927154 to your computer and use it in GitHub Desktop.
Save shiftkey/927154 to your computer and use it in GitHub Desktop.
Comparing the behaviour between IEnumerable<T> and List<T>
public ObservableCollection(IEnumerable<T> collection)
{
this._monitor = new SimpleMonitor<T>();
if (collection == null)
{
throw new ArgumentNullException("collection");
}
this.CopyFrom(collection);
}
public ObservableCollection(List<T> list)
: base((list != null) ? new List<T>(list.Count) : list)
{
this._monitor = new SimpleMonitor<T>();
this.CopyFrom(list);
}
// which both use
private void CopyFrom(IEnumerable<T> collection)
{
IList<T> items = base.Items;
if ((collection != null) && (items != null))
{
using (IEnumerator<T> enumerator = collection.GetEnumerator())
{
while (enumerator.MoveNext())
{
items.Add(enumerator.Current);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment