由网友(memories°(落寞的回忆))分享简介:是否有一个内置的功能在.NET 2.0,将采取两个阵列,并将它们合并成一个阵列?Is there a built in function in .NET 2.0 that will take two arrays and merge them into one array?的阵列都是相同类型的。我从我的code基一...
是否有一个内置的功能在.NET 2.0,将采取两个阵列,并将它们合并成一个阵列?
Is there a built in function in .NET 2.0 that will take two arrays and merge them into one array?
的阵列都是相同类型的。我从我的code基一种广泛使用的功能,让这些阵列,并不能修改该函数返回的数据以不同的格式。
The arrays are both of the same type. I'm getting these arrays from a widely used function within my code base and can't modify the function to return the data in a different format.
我在寻找,以避免写我自己的功能,如果能够实现这一点。
I'm looking to avoid writing my own function to accomplish this if possible.
推荐答案
如果你可以操纵的阵列之一,您可以在执行复制前调整其大小:
If you can manipulate one of the arrays, you can resize it before performing the copy:
T[] array1 = getOneArray();
T[] array2 = getAnotherArray();
int array1OriginalLength = array1.Length;
Array.Resize<T>(ref array1, array1OriginalLength + array2.Length);
Array.Copy(array2, 0, array1, array1OriginalLength, array2.Length);
另外,你可以做一个新的数组
Otherwise, you can make a new array
T[] array1 = getOneArray();
T[] array2 = getAnotherArray();
T[] newArray = new T[array1.Length + array2.Length];
Array.Copy(array1, newArray, 0);
Array.Copy(array2, 0, newArray, array1.Length, array2.Length);
更多关于MSDN 可用阵列的方法。
相关推荐
最新文章