如何阵列的一部分复制到C#另一个数组? [英] How to copy part of an array to another array in C#?
本文介绍了如何阵列的一部分复制到C#另一个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何阵列的一部分复制到另一个阵列?
考虑我在
INT [] A = {1,2,3,4,5};
现在,如果我给数组的开始索引和结束索引 A
它应该被复制到另一个阵列。
一样,如果我给开始指数1和结束指数3,元素2,3,4应该被复制的新阵列中的
解决方案
INT [] B = INT新[3];
Array.Copy(一,1,B,0,3);
- A =源阵列
- 1 =启动源数组索引
- B =目标数组
- 0 =启动目标数组索引
- 3 =元素复制
How can I copy a part of an array to another array?
Consider I'm having
int[] a = {1,2,3,4,5};
Now if I give the start index and end index of the array a
it should get copied to another array.
Like if I give start index as 1 and end index as 3, the elements 2, 3, 4 should get copied in the new array.
解决方案
int[] b = new int[3];
Array.Copy(a, 1, b, 0, 3);
- a = source array
- 1 = start index in source array
- b = destination array
- 0 = start index in destination array
- 3 = elements to copy
这篇关于如何阵列的一部分复制到C#另一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文