Get ArraySegment values

3

When creating a ArraySegment , I'd like to get the new array created, but when using:

meuSegmento.Array;

the original array is returned and not the created thread.

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" }
    
asked by anonymous 18.02.2016 / 12:59

1 answer

2

Do this:

string[] meuArray = {"stack", "overflow","em", "português"};
var meuSegmento = new ArraySegment<string>(meuArray, 2, (meuArray.Length - 2));
string[] arraySegmentado = meuSegmento.ToArray();

See working on dotNetFiddle .

But there you will do something that probably was I was wanting to avoid . There is no free lunch. As I said there, perhaps the need requires a completely different data structure.

You may have to live with low performance. Not every problem can be solved as we wish. There is probably a suitable framework, you just need to see if it pays off the work of implementing it if it is not language ready.

Maybe the problem is another one and a total re-planning is needed.

    
18.02.2016 / 13:32