Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public sealed class ReadOnlyList<T>
- {
- private readonly T[] _backend;
- private readonly int _length;
- public ReadOnlyList([NotNull] T[] backend)
- :
- this(backend, backend.Length)
- {
- }
- public ReadOnlyList([NotNull] T[] backend, int length)
- {
- ThrowIf.Argument.IsNull(backend, nameof(backend));
- ThrowIf.Argument.OutOfRange(length, 0, backend.Length, nameof(length));
- _backend = backend;
- _length = length;
- }
- public ReadOnlyList([NotNull] IEnumerable<T> source)
- {
- ThrowIf.Argument.IsNull(source, nameof(source));
- _backend = source.ToArray();
- _length = _backend.Length;
- }
- [Pure]
- public ArrayEnumerator<T> GetEnumerator()
- {
- return new ArrayEnumerator<T>(_backend, _length);
- }
- [Pure]
- public ReadOnlySpan<T> Access()
- {
- return _backend.AsSpan(0, _length);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement