How to get a sub-array from an existing array in C# without copying? -
my question similar getting sub-array existing array although little different notion important in case - can't use memory copying.
let's have array x
of 10000 elements, need array y
contains 9000 elements x
, starting x
's index 500.
but don't want copy part of x
new array y
, don't want use array.copy, array.clone, system.block.copy, ienumerables etc. want y
reference x - y[0]
in fact x[500]
, y[1]
corresponds x[501]
, ..., y[9000]
x[9500]
.
thus, example changing value of x[100]
@ same time change value of y[600]
. how can achieve in c#?
you wrap in object this:
class view<t> { private t[] _array; private long _start; private long _length; public view(t[] array, long start, long length) { ... } public t this[long index] { { if (/*do bounds check here*/) { return _array[_start + index]; } } } }
this won't array, projection of one.
Comments
Post a Comment