How to Concatenate Strings in C# using LINQ?

Assume that you have an array/List of string which needs to be concatenated. One can concatenate strings using + operator, StringBuilder etc. . . . How about concatenating strings using LINQ?

Below is a sample source code that demonstrates how to concatenate strings in C# using LINQ?

How to Concatenate Strings in C# using LINQ?

using System;

using System.Collections.Generic;

using System.Data;

using System.Linq;

namespace AbundantCode

{

internal class Program

{

//How to Concatenate Strings in C# using LINQ?

private static void Main(string[] args)

{

string[] Phrases = { "AbundantCode", "Website", "for", "Programmers" };

var Result = Phrases.Aggregate((now, nextitem) => now + " " + nextitem);

Console.WriteLine(Result);

Console.ReadLine();

}

}

}
How to Concatenate Strings in C# using LINQ?
%d bloggers like this: