This documentation is archived and is not being maintained.

String.Concat Method (String[])

.NET Framework 1.1

Concatenates the elements of a specified String array.

[Visual Basic]
Overloads Public Shared Function Concat( _
   ByVal ParamArray values() As String _
) As String
[C#]
public static string Concat(
   params string[] values
);
[C++]
public: static String* Concat(
 String* values __gc[]
);
[JScript]
public static function Concat(
   values : String[]
) : String;

Parameters

values
An array of String instances.

Return Value

The concatenated elements of values.

Exceptions

Exception Type Condition
ArgumentNullException values is a null reference (Nothing in Visual Basic).

Remarks

An Empty string is used in place of any null object in the array.

Example

The following code example demonstrates the use of the Concat method with a String array.

[Visual Basic] 
Imports System

Public Class ConcatTest
    
    Public Shared Sub Main()
        Dim s As String() = {"hello ", "and ", "welcome ", "to ", "this ", "demo! "}
        
        ' make an array of strings. Note that we have included spaces
        
        ' put all the strings together
        Console.WriteLine(String.Concat(s))
        
        ' sort the strings, and put them together
        Array.Sort(s)
        Console.WriteLine(String.Concat(s))
    End Sub 'Main
End Class 'ConcatTest

[C#] 
using System;

public class ConcatTest {
    public static void Main() {

        // make an array of strings. Note that we have included spaces
        string [] s = { "hello ", "and ", "welcome ", "to ", "this ", "demo! " };

        // put all the strings together
        Console.WriteLine(string.Concat(s));

        // sort the strings, and put them together
        Array.Sort(s);
        Console.WriteLine(string.Concat(s));
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;

int main()
{
   // make an array of strings. Note that we have included spaces
   String* s[] = { S"hello ", S"and ", S"welcome ", S"to ", S"this ", S"demo! " };

   // put all the strings together
   Console::WriteLine(String::Concat(s));

   // sort the strings, and put them together
   Array::Sort(s);
   Console::WriteLine(String::Concat(s));
}

[JScript] 
import System;

public class ConcatTest {
    public static function Main() : void {

        // make an array of strings. Note that we have included spaces
        var s : String [] = [ "hello ", "and ", "welcome ", "to ", "this ", "demo! "];

        // put all the strings together
        Console.WriteLine(System.String.Concat(s));

        // sort the strings, and put them together
        System.Array.Sort(s);
        Console.WriteLine(System.String.Concat(s));
    }
}
ConcatTest.Main();

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

String Class | String Members | System Namespace | String.Concat Overload List | Join

Show: