String.Join Method
- Reference
Please rate your experience
Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services. Privacy policy.
Thank you.
Definition
Important
Some information relates to prerelease product that may be substantially modified before its released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Concatenates the elements of a specified array or the members of a collection, using the specified separator between each element or member.
In this article
Overloads
Join[Char, Object[]] |
Concatenates the string representations of an array of objects, using the specified separator between each member. |
Join[Char, String[]] |
Concatenates an array of strings, using the specified separator between each member. |
Join[String, IEnumerable] |
Concatenates the members of a constructed IEnumerable collection of type String, using the specified separator between each member. |
Join[String, Object[]] |
Concatenates the elements of an object array, using the specified separator between each element. |
Join[String, String[]] |
Concatenates all the elements of a string array, using the specified separator between each element. |
Join[Char, String[], Int32, Int32] |
Concatenates an array of strings, using the specified separator between each member, starting with the element in value located at the startIndex position, and concatenating up to count elements. |
Join[String, String[], Int32, Int32] |
Concatenates the specified elements of a string array, using the specified separator between each element. |
Join[Char, IEnumerable] |
Concatenates the members of a collection, using the specified separator between each member. |
Join[String, IEnumerable] |
Concatenates the members of a collection, using the specified separator between each member. |
Join[Char, Object[]]
Concatenates the string representations of an array of objects, using the specified separator between each member.
Parameters
The character to use as a separator. separator is included in the returned string only if value has more than one element.
An array of objects whose string representations will be concatenated.
Returns
StringA string that consists of the elements of values delimited by the separator character.
-or-
Empty if values has zero elements.
Exceptions
value is null.
The length of the resulting string overflows the maximum allowed length [MaxValue].
Applies to
Join[Char, String[]]
Concatenates an array of strings, using the specified separator between each member.
Parameters
The character to use as a separator. separator is included in the returned string only if value has more than one element.
An array of strings to concatenate.
Returns
StringA string that consists of the elements of value delimited by the separator character.
-or-
Empty if value has zero elements.
Exceptions
value is null.
The length of the resulting string overflows the maximum allowed length [MaxValue].
Applies to
Join[String, IEnumerable]
Concatenates the members of a constructed IEnumerable collection of type String, using the specified separator between each member.
Parameters
The string to use as a separator.separator is included in the returned string only if values has more than one element.
A collection that contains the strings to concatenate.
Returns
StringA string that consists of the elements of values delimited by the separator string.
-or-
Empty if values has zero elements.
AttributesExceptions
values is null.
The length of the resulting string overflows the maximum allowed length [MaxValue].
Examples
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 object of type String, which it then passes to the Join[String, IEnumerable] method.
using System; using System.Collections.Generic; public class Example { public static void Main[] { int maxPrime = 100; List primes = GetPrimes[maxPrime]; Console.WriteLine["Primes less than {0}:", maxPrime]; Console.WriteLine[" {0}", String.Join[" ", primes]]; } private static List GetPrimes[int maxPrime] { Array values = Array.CreateInstance[typeof[int], new int[] { maxPrime - 1}, new int[] { 2 }]; // Use Sieve of Eratosthenes to determine prime numbers. for [int ctr = values.GetLowerBound[0]; ctr string Public Shared Function Join [separator As String, ParamArray values As Object[]] As StringParameters
The string to use as a separator. separator is included in the returned string only if values has more than one element.
An array that contains the elements to concatenate.
Returns
StringA string that consists of the elements of values delimited by the separator string.
-or-
Empty if values has zero elements.
-or-
.NET Framework only: Empty if the first element of values is null.
AttributesExceptions
values is null.
The length of the resulting string overflows the maximum allowed length [MaxValue].
Examples
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 integer array, which it then passes to the Join[String, Object[]] method.
using System; using System.Collections.Generic; public class Example { public static void Main[] { int maxPrime = 100; int[] primes = GetPrimes[maxPrime]; Console.WriteLine["Primes less than {0}:", maxPrime]; Console.WriteLine[" {0}", String.Join[" ", primes]]; } private static int[] GetPrimes[int maxPrime] { Array values = Array.CreateInstance[typeof[int], new int[] { maxPrime - 1}, new int[] { 2 }]; // Use Sieve of Eratosthenes to determine prime numbers. for [int ctr = values.GetLowerBound[0]; ctr -> string Public Shared Function Join[Of T] [separator As Char, values As IEnumerable[Of T]] As StringType Parameters
The type of the members of values.
Parameters
The character to use as a separator. separator is included in the returned string only if values has more than one element.
A collection that contains the objects to concatenate.
Returns
StringA string that consists of the members of values delimited by the separator character.
-or-
Empty if values has no elements.
Exceptions
values is null.
The length of the resulting string overflows the maximum allowed length [MaxValue].
Applies to
Join[String, IEnumerable]
Concatenates the members of a collection, using the specified separator between each member.
Type Parameters
The type of the members of values.
Parameters
The string to use as a separator. separator is included in the returned string only if values has more than one element.
A collection that contains the objects to concatenate.
Returns
StringA string that consists of the elements of values delimited by the separator string.
-or-
Empty if values has no elements.
AttributesExceptions
values is null.
The length of the resulting string overflows the maximum allowed length [MaxValue].
Examples
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 object of type integer, which it then passes to the Join[String, IEnumerable] method.
using System; using System.Collections.Generic; public class Example { public static void Main[] { int maxPrime = 100; List primes = GetPrimes[maxPrime]; Console.WriteLine["Primes less than {0}:", maxPrime]; Console.WriteLine[" {0}", String.Join[" ", primes]]; } private static List GetPrimes[int maxPrime] { Array values = Array.CreateInstance[typeof[int], new int[] { maxPrime - 1}, new int[] { 2 }]; // Use Sieve of Eratosthenes to determine prime numbers. for [int ctr = values.GetLowerBound[0]; ctr