本文概述
在LINQ中, Concat方法或运算符用于将两个集合元素串联或附加到单个集合中, 并且不会从两个序列中删除重复项。
这是LINQ Concat方法的图形表示。

在上图中, 两个元素列表组合成一个集合。
LINQ Concat方法的语法
var result = arr1.Concat(arr2);
在以上语法中, 我们将两个列表串联为一个列表。
LINQ Concat方法的示例
这是LINQ Concat方法的示例。
using System;
using System. Collections;
using System.Collections.Generic;
using System. Linq;
using System. Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Programme2
{
static void Main(string[] args)
{
//here we create two array type of string variable array1 and array2
string[] array1 = { "a", "b", "c", "d" };
string[] array2 = { "c", "d", "e", "f" };
/*here we will concat two array with the help of 'concat'
method and store the output in 'result' variable*/
var result = array1.Concat(array2);
//foreach loop will print the value of result
foreach (var item in result)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}
在上面的示例中, 我们使用concat方法将两个序列” array1″, ” array2″串联为一个序列。
输出
