/// <summary> /// Creates a new span over the portion of the target array beginning /// at 'start' index and ending at 'end' index (exclusive). /// </summary> /// <param name="array">The target array.</param> /// <param name="start">The index at which to begin the span.</param> /// <param name="length">The number of items in the span.</param> /// <exception cref="System.ArgumentException"> /// Thrown if the 'array' parameter is null. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified start or end index is not in range (<0 or >&eq;length). /// </exception> public Span(T[] array, int start, int length) { Contract.Requires(array != null); Contract.RequiresInInclusiveRange(start, array.Length); Contract.RequiresNonNegative(length); Contract.RequiresInInclusiveRange(start + length, array.Length); if (start < array.Length) { _object = array; _offset = new UIntPtr( (uint)(SpanHelpers <T> .OffsetToArrayData + (start * PtrUtils.SizeOf <T>()))); Length = length; } else { _object = null; _offset = UIntPtr.Zero; Length = 0; } }