Created
November 25, 2016 08:37
-
-
Save bitbonk/6d4be0d6427effb5d9b6e937a36e4cc1 to your computer and use it in GitHub Desktop.
ctor geruden von ToList()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List(IEnumerable<T> collection) | |
{ | |
if (collection == null) | |
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection); | |
ICollection<T> objs = collection as ICollection<T>; | |
if (objs != null) | |
{ | |
int count = objs.Count; | |
if (count == 0) | |
{ | |
this._items = List<T>._emptyArray; | |
} | |
else | |
{ | |
this._items = new T[count]; | |
objs.CopyTo(this._items, 0); | |
this._size = count; | |
} | |
} | |
else | |
{ | |
this._size = 0; | |
this._items = List<T>._emptyArray; | |
foreach (T obj in collection) | |
this.Add(obj); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment