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


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Concatenates the members of a constructed IEnumerable<T> collection of type String, using the specified separator between each member.

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

static String^ Join(
	String^ separator,
	IEnumerable<String^>^ values


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.

Type: System.Collections.Generic::IEnumerable<String^>^

A collection that contains the strings 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.

Exception Condition

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(String^, IEnumerable<String^>^) is a convenience method that lets you concatenate each element in an IEnumerable(Of String) collection without first converting the elements to a string array. It is particularly useful with Language-Integrated Query (LINQ) query expressions. The following example passes a List(Of String) object that contains either the uppercase or lowercase letters of the alphabet to a lambda expression that selects letters that are equal to or greater than a particular letter (which, in the example, is "M"). The IEnumerable(Of String) collection returned by the Enumerable::Where<TSource> method is passed to the Join(String^, IEnumerable<String^>^) method to display the result as a single string.

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 String, which it then passes to the Join(String^, IEnumerable<String^>^) 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
Available since 4.0
Windows Phone Silverlight
Available since 7.1
Windows Phone
Available since 8.1
Return to top