Choosing Linq Compound

How can I concatenate two arrays into one array while choosing a join ( without using Union ) (question was asked in an interview).

    var num1 = new int[] { 12, 3, 4, 5 };
    var num2 = new int[] { 1, 33, 6, 10 };

      

I tried like

    var pairs = from a in num1 from b in num2  select new {combined={a,b}};

      

Expected: should be {12,3,4,5,1,33,6,10}

+2


source to share


3 answers


num1.Concat( num2 );

      



I'm not sure if there is a related LINQ keyword.

+6


source


If you just want to concatenate 2 arrays into a new array containing elements from both arrays use concat.



var combined = num1.Concat(num2);
var combinedAsArray = combined.ToArray();

      

+5


source


var newArray = (from number in num1.Concat (num2) select number) .ToArray ();

-1


source







All Articles