C# String Concat(IEnumerable)
Description
String Concat(IEnumerable <string>)
concatenates
the members of a constructed IEnumerable
Syntax
String.Concat(IEnumerable<String>)
has the following syntax.
[ComVisibleAttribute(false)]
public static string Concat(
IEnumerable<string> values
)
Parameters
String.Concat(IEnumerable<String>)
has the following parameters.
values
- A collection object that implements IEnumerableand whose generic type argument is String.
Returns
String.Concat(IEnumerable<String>)
method returns The concatenated strings in values.
Example
The following code shows how to use String.Concat(IEnumerable<String>)
method.
using System;/*w ww .j a v a 2s . c o m*/
using System.Collections.Generic;
using System.Linq;
public class Example
{
public static void Main()
{
string output = String.Concat( GetAlphabet(true).Where( letter =>
letter.CompareTo("M") >= 0));
Console.WriteLine(output);
}
private static List<string> GetAlphabet(bool upper)
{
List<string> alphabet = new List<string>();
int charValue = upper ? 65 : 97;
for (int ctr = 0; ctr <= 25; ctr++)
alphabet.Add(Convert.ToChar(charValue + ctr).ToString());
return alphabet;
}
}
The code above generates the following result.