C# String Concat(IEnumerable)

Description

String Concat(IEnumerable <string>) concatenates the members of a constructed IEnumerable collection of type String.

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 IEnumerable and 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.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version