Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String::Join<T> Method (String^, IEnumerable<T>^)

 

Concatenates the members of a collection, using the specified separator between each member.

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

public:
generic<typename T>
[ComVisibleAttribute(false)]
static String^ Join(
	String^ separator,
	IEnumerable<T>^ values
)

Parameters

separator
Type: System::String^

The string to use as a separator.separator is included in the returned string only if values has more than one element.

values
Type: System.Collections.Generic::IEnumerable<T>^

A collection that contains the objects to concatenate.

Return Value

Type: System::String^

A string that consists of the members of values delimited by the separator string. If values has no members, the method returns String::Empty.

Type Parameters

T

The type of the members of values.

Exception Condition
ArgumentNullException

values is null.

If separator is null, an empty string (String::Empty) is used instead. If any member of values is null, an empty string is used instead.

Join<T>(String^, IEnumerable<T>^) is a convenience method that lets you concatenate each member of an IEnumerable<T> collection without first converting them to strings. The string representation of each object in the IEnumerable<T> collection is derived by calling that object's ToString method.

This method is particular useful with Language-Integrated Query (LINQ) query expressions. For example, the following code 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 that contains a number of Animal objects. The Enumerable::Where<TSource> extension method is called to extract the Animal objects whose Order property equals "Rodent". The result is passed to the Join<T>(String^, IEnumerable<T>^) method.

No code example is currently available or this language may not be supported.

The following example uses the Sieve of Eratosthenes algorithm to calculate the prime numbers that are less than or equal to 100. It assigns the result to a List<T> object of type integer, which it then passes to the Join<T>(String^, IEnumerable<T>^) method.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 4.0
Windows Phone Silverlight
Available since 7.1
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft