We are trying to concatenate
two arrays, tried the concatenate
, append to list join array without success. Is there an easy function to turn two lists {a,b,c} and {1,2,3} into {a1,b2,c3}? The arrays are multiples within CDT's
and we're combining a text array with an integer array.
Asked
Active
Viewed 77 times
1

Siavash
- 2,813
- 4
- 29
- 42

Lalit Yadav
- 21
- 5
-
Could u plz show some code that you have done so far? – er-sho Oct 30 '18 at 10:16
-
@Rene I'm sure _What is the use of Enumerable.Zip extension_ wasn't the question and there are other ways to solve this than `Zip()`. No exact duplicate imo – fubo Oct 30 '18 at 10:20
-
@fubo though it wasn't the question, the linked dup is a canonical question that solves OP's problem and in fact _answers_ the question. The answers there are almost 100% the same (including sample data) as given here. And I don't want to _delete_ this question, it's a good signpost to find the canonical answer. – René Vogt Oct 30 '18 at 10:27
-
@RenéVogt: however, i doubt if it's the right way to close as a duplicate if it's actually not a duplicate of that. It's like someone asks "how to repair my car gear" and it's closed as a duplicate of "what is the use of a car gear"(where also is shown how to repair it). – Tim Schmelter Oct 30 '18 at 10:43
2 Answers
2
Try Linq Zip()
which
Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.
string[] array1 = { "a", "b", "c" };
string[] array2 = { "1", "2", "3" };
string[] result = array1.Zip(array2, (x, y) => x + y).ToArray();
in this case it concartenates two strings (x, y) => x + y

fubo
- 44,811
- 17
- 103
- 137
0
Here I have assumed that both arrats have the same length:
List<string> result;
for(int i=0;i<array1.Length;i++)
result.Add(${array2[i]}{array1[i]});

Ashkan Mobayen Khiabani
- 33,575
- 33
- 102
- 171