Q:

C# program to demonstrate the example of Linq Concat() method

belongs to collection: C# LINQ Programs

0

C# program to demonstrate the example of Linq Concat() method

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to demonstrate the Linq Concat() method, is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# Program to demonstrate the Linq Concat() method.

using System;
using System.Linq;
using System.Collections.Generic;

class Demo
{
    static void Main(string[] args)
    {
        List<string> List1 = new List<string>() { "Abc", "Pqr", "Lmn", "Xyz" };
        List<string> List2 = new List<string>() { "Abc", "pqr" , "KLP" };

        var result = List1.Concat(List2);

        foreach (string value in result)
        {
            Console.WriteLine(value + " ");
        } 
    }
}

Output:

Abc
Pqr
Lmn
Xyz
Abc
pqr
KLP
Press any key to continue . . .

Explanation:

In the above program, we create two lists list1 and list2 of string values. Here we used Linq Concat() method to append the value of list2 with list1.

var result = List1.Concat(List2);

foreach (string value in result)
{
    Console.WriteLine(value + " ");
} 

In the above code, we appended the values of list2 to the list1 and assigned to the result then print them on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# LINQ Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to sort a list of integers using the Li... >>
<< C# program to demonstrate the example of Linq Unio...