Concat method merge results from two separate LINQ queries into single result set - LINQ

Q.  How you can merge the results from two separate LINQ queries into a single result set.
- Published on 31 Aug 15

a. Use the ToList method.
b. Use the DataContractJsonSerializer class.
c. Use the XElement class.
d. Use the Concat method.

ANSWER: Use the Concat method.
 
Concat method is used to merge two separate lists together to form a single list.

class Program
{
static void Main()
{
List<string> list1 = new List<string>();
list1.Add( " A " );
list1.Add( " B " );

List<string> list2 = new List<string>();
list2.Add( " C " );
list2.Add( " D " );

var result = list1.Concat(list2);
List<string>finalList = result.ToList();
foreach (var entry in finalList)
{
Console.WriteLine(entry);
}
}
}

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)