/ 猿问

合并.NET中的两个数组

2019-10-17 12:57:27

.NET 2.0中是否有内置函数将两个数组合并为一个数组？

3 回答

int[] front = { 1, 2, 3, 4 };

int[] back = { 5, 6, 7, 8 };

int[] combined = front.Concat(back).ToArray();

int[] front = { 1, 2, 3, 4 };

int[] back = { 5, 6, 7, 8 };

int[] combined = new int[front.Length + back.Length];

Array.Copy(front, combined, front.Length);

Array.Copy(back, 0, combined, front.Length, back.Length);

1 反对 回复 2019-10-17

var arr1 = new[] { 1, 2, 3, 4, 5 };

var arr2 = new[] { 6, 7, 8, 9, 0 };

var arr = arr1.Union(arr2).ToArray();

1 反对 回复 2019-10-17

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);

T[] array1 = getOneArray();

T[] array2 = getAnotherArray();

T[] newArray = new T[array1.Length + array2.Length];

Array.Copy(array1, newArray, array1.Length);

Array.Copy(array2, 0, newArray, array1.Length, array2.Length);

• 3 回答
• 1 关注
• 263 浏览

0/150