Example #1
0
            private TResult[] LazyToArray()
            {
                Debug.Assert(_source.GetCount(onlyIfCheap: true) == -1);

                var builder = new LargeArrayBuilder <TResult>(initialize: true);

                foreach (TSource input in _source)
                {
                    builder.Add(_selector(input));
                }
                return(builder.ToArray());
            }
Example #2
0
            public TResult[] ToArray()
            {
                int count = _source.GetCount(onlyIfCheap: true);

                switch (count)
                {
                case -1:
                    return(EnumerableHelpers.ToArray(this));

                case 0:
                    return(Array.Empty <TResult>());

                default:
                    TResult[] array = new TResult[count];
                    int       index = 0;
                    foreach (TSource input in _source)
                    {
                        array[index] = _selector(input);
                        ++index;
                    }
                    return(array);
                }
            }