Home > DeveloperSection > Forums > Create new reference to array with different length
lois waisbrooker
lois waisbrooker

Total Post:70

Posted on    October-05-2013 3:37 AM

 C# C# 

 1 Reply(s)
 892  View(s)
Rate this:

Given some array:

int[] array = new int[8000];

Is it possible to refer to a new array such that:

int[] array2 = Array.SameReferenceDifferentLength(array, 4000);

F Scott Fitzgerald
F Scott Fitzgerald

Total Post:29

Posted on    October-05-2013 4:25 AM

var a = new string[] { "a", "b", "c", "d", "e" };
var b = new ArraySegment<string>(a, 1, 3);
foreach (var s in b)

This makes a shallow reference to the specified range of the array. That is, it doesn't copy the array data.

If you want to index an ArraySegment<T>, you can cast it to a IList<T> then use the indexer provided by that interface.


Don't want to miss updates? Please click the below button!

Follow MindStick