/// <summary>Returns a sub-slice of this slice. This method cannot be used /// to expand the range of the original slice.</summary> public ListSlice <T> Slice(int start, int length) { CheckParam.IsNotNegative("length", length); if (start > _length) { length = 0; } else if (length > _length - start) { length = _length - start; } return(new ListSlice <T>(_obj, _start + start, length)); }
public static void CopyTo <T>(this IReadOnlyCollection <T> c, T[] array, int arrayIndex) { int space = array.Length - arrayIndex; if (c.Count > space) { CheckParam.ThrowBadArgument(nameof(array), "CopyTo: array is too small ({0} < {1})", space, c.Count); } CheckParam.IsNotNegative(nameof(arrayIndex), arrayIndex); foreach (var item in c) { array[arrayIndex++] = item; } }
public IntRange Slice(int start, int count) { CheckParam.IsNotNegative("start", start); CheckParam.IsNotNegative("count", count); if (start > _count) { count = 0; } else if (count > _count - start) { count = _count - start; } return(new IntRange(_start + start, count)); }
/// <summary>Initializes a ListSourceSlice object which provides a view on part of another list.</summary> /// <param name="list">A list to wrap (must not be null).</param> /// <param name="start">An index into the original list. this[0] will refer to that index. /// This cannot be negative, but it can be beyond the end of the list.</param> /// <param name="length">The number of elements to allow access to. If /// start+length exceeds the list size, length is reduced immediately. /// Thus, if the original list expands after the slice is created, the /// slice's Count never increases to match the original list.</param> /// <exception cref="IndexOutOfRangeException">'start' or 'length' was negative.</exception> public ListSlice(IList <T> list, int start, int length) : base(list) { CheckParam.IsNotNegative("length", length); CheckParam.IsNotNegative("start", start); int count = list.Count; if (start > count) { length = 0; } else if (length > count - start) { length = count - start; } _start = start; _length = length; }
InternalDList <T> Slice(int start, int subcount) { CheckParam.IsNotNegative("start", start); CheckParam.IsNotNegative("subcount", subcount); if (start > _count) { start = _count; } if (subcount > _count - start) { subcount = _count - start; } return(new InternalDList <T> { _start = IncMod(_start, start), _count = subcount, _array = _array }); }
public new StringSlice Slice(int startIndex, int length) { CheckParam.IsNotNegative("startIndex", startIndex); if (length <= 0) { return(new StringSlice("", 0, length)); } StringBuilder sb = new StringBuilder(Math.Min(length, 1024)); for (int i = startIndex; i < startIndex + length; i++) { if ((uint)(i - _blkStart) >= (uint)_blkLen) { if (!Access(i)) { break; } } sb.Append(_blk[i - _blkStart]); } return(sb.ToString()); }