3

Possible Duplicate:
How to copy part of an array to another array in C#?

if i have:

string[] myArray =  . . . .

which is an array with a length of 10. how can i create a new string array that is the 2nd to 10th elements of the first array without looping?

Community
  • 1
  • 1
leora
  • 188,729
  • 360
  • 878
  • 1,366

2 Answers2

10

Use System.Array.Copy:

string[] myArray = ....
string[] copy = new string[10];
Array.Copy(myArray, 2, copy, 0, 10);    
codekaizen
  • 26,990
  • 7
  • 84
  • 140
0

Array.Copy

(But note, it will be looping under the covers, just optimally so).

Example.

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • lol...Just got to it 51s before you did....I like the function but, prefer loops as I can address them how I need. –  Jul 12 '10 at 05:06