System.Runtime.CompilerServices.ReadOnlyCollectionBuilder.ToReadOnlyCollection C# (CSharp) Method

ToReadOnlyCollection() public method

Creates a ReadOnlyCollection{T} containing all of the elements of the ReadOnlyCollectionBuilder{T}, avoiding copying the elements to the new array if possible. Resets the ReadOnlyCollectionBuilder{T} after the ReadOnlyCollection{T} has been created.
public ToReadOnlyCollection ( ) : ReadOnlyCollection
return ReadOnlyCollection
        public ReadOnlyCollection<T> ToReadOnlyCollection()
        {
            // Can we use the stored array?
            T[] items;
            if (_size == _items.Length)
            {
                items = _items;
            }
            else
            {
                items = ToArray();
            }
            _items = Array.Empty<T>();
            _size = 0;
            _version++;

            return new TrueReadOnlyCollection<T>(items);
        }