public static void Clear(Array array, int index, int length) { if (array == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if (length < 0) { ThrowHelper.ThrowIndexOutOfRangeException(); } int low = array.GetLowerBound(0); if (index < low) { ThrowHelper.ThrowIndexOutOfRangeException(); } index = index - low; // re-ordered to avoid possible integer overflow if (index > array.Length - length) { ThrowHelper.ThrowIndexOutOfRangeException(); } ClearInternal(array, index, length); }
/// <summary> /// Returns a reference to specified element of the Span. /// </summary> /// <param name="index"></param> /// <returns></returns> /// <exception cref="System.IndexOutOfRangeException"> /// Thrown when index less than 0 or index greater than or equal to Length /// </exception> // TODO: https://github.com/dotnet/corefx/issues/13681 // Until we get over the hurdle of C# 7 tooling, this temporary method will simulate the intended "ref T" indexer for those // who need bypass the workaround for performance. //[MethodImpl(MethodImplOptions.AggressiveInlining)] public ref T GetItem(int index) { if ((uint)index >= ((uint)_length)) { ThrowHelper.ThrowIndexOutOfRangeException(); } return(ref Unsafe.Add(ref _pointer.Value, index)); }
public char this [int index] { [Intrinsic] get { if ((uint)index >= _stringLength) { ThrowHelper.ThrowIndexOutOfRangeException(); } return(Unsafe.Add(ref _firstChar, index)); } }
public char this[int index] { [Intrinsic] get { if ((uint)index >= (uint)_stringLength) { ThrowHelper.ThrowIndexOutOfRangeException(); } return(Unsafe.Add(ref _firstChar, (nint)(uint)index /* force zero-extension */)); } }
/// <summary> /// Fetches the element at the specified index. /// </summary> /// <exception cref="System.IndexOutOfRangeException"> /// Thrown when the specified <paramref name="index"/> is not in range (<0 or >&eq;Length). /// </exception> public T this[int index] { get { if ((uint)index >= (uint)_length) { ThrowHelper.ThrowIndexOutOfRangeException(); } return(Unsafe.Add(ref DangerousGetPinnableReference(), index)); } }
/// <summary> /// Fetches the element at the specified index. /// </summary> /// <exception cref="System.IndexOutOfRangeException"> /// Thrown when the specified <paramref name="index"/> is not in range (<0 or >&eq;Length). /// </exception> public T this[int index] { get { if ((uint)index >= (uint)_length) { ThrowHelper.ThrowIndexOutOfRangeException(); } return(Unsafe.Add(ref GetRawPointer(), index)); } }
/// <summary> /// Returns a reference to specified element of the Span. /// </summary> /// <param name="index"></param> /// <returns></returns> /// <exception cref="System.IndexOutOfRangeException"> /// Thrown when index less than 0 or index greater than or equal to Length /// </exception> public ref T this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if ((uint)index >= (uint)_length) { ThrowHelper.ThrowIndexOutOfRangeException(); } return(ref Unsafe.Add(ref _pointer.Value, index)); } }
/// <summary> /// Returns the specified element of the read-only span. /// </summary> /// <param name="index"></param> /// <returns></returns> /// <exception cref="System.IndexOutOfRangeException"> /// Thrown when index less than 0 or index greater than or equal to Length /// </exception> public ref readonly T this[int index] { [Intrinsic] [MethodImpl(MethodImplOptions.AggressiveInlining)] [NonVersionable] get { if ((uint)index >= (uint)_length) { ThrowHelper.ThrowIndexOutOfRangeException(); } return(ref Unsafe.Add(ref _pointer.Value, index)); } }
/// <summary> /// Returns a reference to specified element of the Span. /// </summary> /// <param name="index"></param> /// <returns></returns> /// <exception cref="System.IndexOutOfRangeException"> /// Thrown when index less than 0 or index greater than or equal to Length /// </exception> public ref T this[int index] { [Intrinsic] [MethodImpl(MethodImplOptions.AggressiveInlining)] [NonVersionable] get { if ((uint)index >= (uint)_length) { ThrowHelper.ThrowIndexOutOfRangeException(); } return(ref Unsafe.Add(ref _reference, (nint)(uint)index /* force zero-extension */)); } }
public ref T GetItem(int index) { if ((uint)index >= ((uint)_length)) { ThrowHelper.ThrowIndexOutOfRangeException(); } if (_pinnable == null) { unsafe { return(ref Unsafe.Add <T>(ref Unsafe.AsRef <T>(_byteOffset.ToPointer()), index)); } } else { return(ref Unsafe.Add <T>(ref Unsafe.AddByteOffset <T>(ref _pinnable.Data, _byteOffset), index)); } }
public static unsafe void Clear(Array array, int index, int length) { if (array == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } int lowerBound = array.GetLowerBound(0); int elementSize = array.GetElementSize(); nuint numComponents = (nuint)Unsafe.As <RawData> (array).Count; int offset = index - lowerBound; if (index < lowerBound || offset < 0 || length < 0 || (uint)(offset + length) > numComponents) { ThrowHelper.ThrowIndexOutOfRangeException(); } ref byte ptr = ref Unsafe.AddByteOffset(ref array.GetRawSzArrayData(), (uint)offset * (nuint)elementSize);
/// <summary> /// Returns the specified element of the read-only span. /// </summary> /// <param name="index"></param> /// <returns></returns> /// <exception cref="System.IndexOutOfRangeException"> /// Thrown when index less than 0 or index greater than or equal to Length /// </exception> public ref readonly T this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if ((uint)index >= ((uint)_length)) { ThrowHelper.ThrowIndexOutOfRangeException(); } if (_pinnable == null) { unsafe { return(ref Unsafe.Add <T>(ref Unsafe.AsRef <T>(_byteOffset.ToPointer()), index)); } } else { return(ref Unsafe.Add <T>(ref Unsafe.AddByteOffset <T>(ref _pinnable.Data, _byteOffset), index)); } } }