Merge sequences using predicate with Zip method.
Here are our arrays to be merged.
int[] intArray = { 10, 20, 30, 40 };
string[] stringArray = { "Jack", "Tim", "Henry", "Tom" };Now let’s use the Zip method to merge both the arrays.
intArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two)
The following is our code.
Example
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
int[] intArray = { 10, 20, 30, 40 };
string[] stringArray = { "Jack", "Tim", "Henry", "Tom" };
var mergedSeq = intArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two);
foreach (var ele in mergedSeq)
Console.WriteLine(ele);
}
}Output
10 Jack 20 Tim 30 Henry 40 Tom