{TOC}
| Namespace: | System.Linq |
| Assembly: | System.Core.dll |
| Extends: | IEnumerable<T> |
Back to
Standard Query Operator IndexEditIntroduction
The ToArray operator creates an array from a sequence. This allows you to force an immediate enumerations over an interator.
EditMethod Signatures
public static TSource[] ToArray<TSource>(
this IEnumerable<TSource> source)EditExceptions
Throws an ArgumentNullException if
source is null.
EditPseudo-code
If
source is null, throw an ArgumentNullException.
If
source is an ICollection type.
If
source has no elements, return an empty array (TSource
0).
Create a new array the same length as source.Count.
Call ICollection.CopyTo which will copy data from the source sequence to a new array.
Return the new array.
Else.
Initialize a new array with a length of 4.
Iterate the source sequence.
If there isn't enough room in the new array to copy the next element, double the size of the new array.
Copy the current element to the new array.
Return the new array.
EditLoop Count
1. All elements in
source are enumerated.
EditCode Samples
TODO: Needs code sample.