public T this[long index] { get { if (_array == null) { throw new InvalidOperationException("Array is null"); } if (index < 0 || index >= _range.Count) { throw new ArgumentOutOfRangeException(); } long[] dimIndices = new long[_arrayInfo.Rank]; _arrayInfo.CalcDimIndices(_range.Index + index, dimIndices); return((T)_array.GetValue(dimIndices)); } set { if (_array == null) { throw new InvalidOperationException("Array is null"); } if (index < 0 || index >= _range.Count) { throw new ArgumentOutOfRangeException(); } long[] dimIndices = new long[_arrayInfo.Rank]; _arrayInfo.CalcDimIndices(_range.Index + index, dimIndices); _array.SetValue(value, dimIndices); } }
/// <summary> /// Adds value to the value of the flat delta index. /// If the value of property Module false and indices out of range then throwing an exception. /// Otherwise, the addition is performed by module the length of the array and exception is not throw. /// </summary> /// <param name="delta"></param> /// <returns></returns> private long AddFlatIndexCore(long delta) { long carry = 0; bool checkOut = _checkOut; if (!checkOut && (delta > _arrayInfo.Length || delta < -_arrayInfo.Length)) { delta %= _arrayInfo.Length; } else if (_arrayInfo.Length == 0) { throw new InvalidOperationException("Operatiois out of range"); } if (delta > 0 && _arrayInfo.Length - _flatIndex < delta + 1) { if (!checkOut) { carry = delta - (_arrayInfo.Length - _flatIndex - 1); } else { throw new InvalidOperationException("Operatiois out of range"); } } else if (delta < 0 && _flatIndex < -delta) { if (!checkOut) { carry = -delta - _flatIndex; } else { throw new InvalidOperationException("Operatiois out of range"); } } _flatIndex += delta > 0 && _arrayInfo.Length - _flatIndex < delta + 1 ? delta - _arrayInfo.Length : delta < 0 && _flatIndex < -delta ? delta + _arrayInfo.Length : delta; if (delta == 1) { _arrayInfo.IncDimIndices(_zeroBased, _dimIndices); } else if (delta == -1) { _arrayInfo.DecDimIndices(_zeroBased, _dimIndices); } else { _arrayInfo.CalcDimIndices(_flatIndex, _zeroBased, _dimIndices); } return(_carry = carry); }