Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ToArray< T >() [5/5]

static T[] System.Collections.Generic.EnumerableHelpers.ToArray< T > ( IEnumerable< T > source,
out int length )
inlinestaticpackage

Definition at line 5 of file EnumerableHelpers.cs.

6 {
7 if (source is ICollection<T> { Count: var count } collection)
8 {
9 if (count != 0)
10 {
11 T[] array = new T[count];
12 collection.CopyTo(array, 0);
13 length = count;
14 return array;
15 }
16 }
17 else
18 {
19 using IEnumerator<T> enumerator = source.GetEnumerator();
20 if (enumerator.MoveNext())
21 {
22 T[] array2 = new T[4]
23 {
24 enumerator.Current,
25 default(T),
26 default(T),
27 default(T)
28 };
29 int num = 1;
30 while (enumerator.MoveNext())
31 {
32 if (num == array2.Length)
33 {
34 int num2 = num << 1;
35 if ((uint)num2 > Array.MaxLength)
36 {
37 num2 = ((Array.MaxLength <= num) ? (num + 1) : Array.MaxLength);
38 }
39 Array.Resize(ref array2, num2);
40 }
41 array2[num++] = enumerator.Current;
42 }
43 length = num;
44 return array2;
45 }
46 }
47 length = 0;
48 return Array.Empty<T>();
49 }

References System.array, System.collection, System.count, System.Collections.Generic.Dictionary< TKey, TValue >.GetEnumerator(), System.length, System.Array.MaxLength, and System.source.