3
By creating a ArraySegment
, would like to get the new array created, but when using:
meuSegmento.Array;
the array original is returned and not the created segment.
string[] meuArray = {"stack", "overflow","em", "português"};
var meuSegmento = new ArraySegment<string>(meuArray, 2, (meuArray.Length - 1));
string[] arraySegmentado = meuSegmento.Segmento; //Quero o seguimento criado: { "em", "português" }
meSegmento.Array was to be right, basically as shown here http://www.dotnetperls.com/arraysegment
– Thiago Friedman
First that the second element should be
new ArraySegment<string>(meuArray, 2, (meuArray.Length - 3));
, since the second parameter is relative to how many elements from index 2 you want to pick up. Second to traverse Arraysegment only using a for as follows:for(var i = segmento.Offset; i < segmento.Count+ segmento.Offset; i++)
. So the real usefulness of Arraysegment would be more for LINQ queries.– Felipe Avelar
@Thiagofriedman, actually no, what the
meuSegmento.Array
returns, according to its reference link, is, precisely, the original vector.– Felipe Avelar
@Felipeavelar did not understand, because his reference to create Arraysegment is the original vector too, ie meuArray
– Thiago Friedman