开发者

copy part of an array into another array [duplicate]

This question already has answers here: Closed 11 years ago. 开发者_Go百科

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?


Use System.Array.Copy:

string[] myArray = ....
string[] copy = new string[10];
Array.Copy(myArray, 2, copy, 0, 10);    


Array.Copy

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

Example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜