String::Join<T> Method (String, IEnumerable<T>)
Concatenates the members of a collection, using the specified separator between each member.
Assembly: mscorlib (in mscorlib.dll)
[ComVisibleAttribute(false)] public: generic<typename T> static String^ Join( String^ separator, IEnumerable<T>^ values )
Type Parameters
- T
The type of the members of values.
Parameters
- separator
- Type: System::String
The string to use as a separator.
- values
- Type: System.Collections.Generic::IEnumerable<T>
A collection that contains the objects to concatenate.
Return Value
Type: System::StringA 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 |
|---|---|
| ArgumentNullException | values is nullptr. |
If separator is nullptr, an empty string (String::Empty) is used instead. If any member of values is nullptr, 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 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.
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.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.