C# String Concat(IEnumerable)

Description

String Concat (IEnumerable ) concatenates the members of an IEnumerable implementation.

Syntax

String.Concat<T>(IEnumerable<T>) has the following syntax.


[ComVisibleAttribute(false)]
public static string Concat<T>(
  IEnumerable<T> values
)

Parameters

String.Concat<T>(IEnumerable<T>) has the following parameters.

  • T - The type of the members of values.
  • values - A collection object that implements the IEnumerable interface.

Returns

String.Concat<T>(IEnumerable<T>) method returns The concatenated members in values.

Example

The following code shows how to use String.Concat<T>(IEnumerable<T>) method.


using System;/*w  w  w .jav  a2 s  . co m*/
using System.Collections.Generic;
using System.Linq;

public class Animal
{
   public string Kind;
   public string Order;

   public Animal(string kind, string order)
   {
      this.Kind = kind;
      this.Order = order;
   }

   public override string ToString()
   {
      return this.Kind;
   }
}

public class Example
{
   public static void Main()
   {
      List<Animal> animals = new List<Animal>();
      animals.Add(new Animal("Squirrel", "Rodent"));
      animals.Add(new Animal("Gray Wolf", "Carnivora"));
      string output = String.Concat(animals.Where( animal => 
                      (animal.Order == "Rodent")));
      Console.WriteLine(output);  
   }
}

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