Freigeben über


String.Concat<T> Method (IEnumerable<T>)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Concatenates the members of an IEnumerable<T> implementation.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<ComVisibleAttribute(False)> _
Public Shared Function Concat(Of T) ( _
    values As IEnumerable(Of T) _
) As String
[ComVisibleAttribute(false)]
public static string Concat<T>(
    IEnumerable<T> values
)

Type Parameters

  • T
    The type of the members of values.

Parameters

Return Value

Type: System.String
The concatenated members in values.

Exceptions

Exception Condition
ArgumentNullException

values is nulla null reference (Nothing in Visual Basic).

Remarks

The method concatenates each object in values; it does not add any delimiters.

An Empty string is used in place of any null argument.

Concat<T>(IEnumerable<T>) is a convenience method that lets you concatenate each element in an IEnumerable<T> collection without first converting the elements to strings. It is particularly useful with Language-Integrated Query (LINQ) query expressions, as the example illustrates. The string representation of each object in the IEnumerable<T> collection is derived by calling that object's ToString method.

Examples

The following example defines a very simple Animal class that contains the name of an animal and the order to which it belongs. It then defines a List<T> object to contain a number of Animal objects. The Enumerable.Where extension method is called to extract the Animal objects whose Order property equals "Rodent". The result is passed to the Concat<T>(IEnumerable<T>) method and displayed to the console.

Version Information

Silverlight

Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.