.NET Framework Class Library  

String.Concat Method

Concatenates one or more instances of String, or the String representations of the values of one or more instances of Object.

Overload List

Creates the String representation of a specified object.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Concat(Object) As String
[C#] public static string Concat(object);
[C++] public: static String* Concat(Object*);
[JScript] public static function Concat(Object) : String;

Concatenates the String representations of the elements in a specified Object array.

Supported by the .NET Compact Framework.

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

Concatenates the elements of a specified String array.

Supported by the .NET Compact Framework.

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

Concatenates the String representations of two specified objects.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Concat(Object, Object) As String
[C#] public static string Concat(object, object);
[C++] public: static String* Concat(Object*, Object*);
[JScript] public static function Concat(Object, Object) : String;

Concatenates two specified instances of String.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Concat(String, String) As String
[C#] public static string Concat(string, string);
[C++] public: static String* Concat(String*, String*);
[JScript] public static function Concat(String, String) : String;

Concatenates the String representations of three specified objects.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Concat(Object, Object, Object) As String
[C#] public static string Concat(object, object, object);
[C++] public: static String* Concat(Object*, Object*, Object*);
[JScript] public static function Concat(Object, Object, Object) : String;

Concatenates three specified instances of String.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Concat(String, String, String) As String
[C#] public static string Concat(string, string, string);
[C++] public: static String* Concat(String*, String*, String*);
[JScript] public static function Concat(String, String, String) : String;

[C++] Concatenates the String representations of three specified objects and a variable-length parameter list. This method is not CLS-compliant.

[C++] public: static String* Concat(Object*, Object*, Object*, Object*, ...);

Concatenates four specified instances of String.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Concat(String, String, String, String) As String
[C#] public static string Concat(string, string, string, string);
[C++] public: static String* Concat(String*, String*, String*, String*);
[JScript] public static function Concat(String, String, String, String) : String;

Example

[Visual Basic, C#, C++] The following example demonstrates the Concat method.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Concat. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
Imports Microsoft.VisualBasic
 _

Class stringConcat5
   
   Public Shared Sub Main()
      Dim i As Integer = - 123
      Dim o As [Object] = i
      Dim objs() As [Object] = {- 123, - 456, - 789}
      
      Console.WriteLine("Concatenate 1, 2, and 3 objects:")
      Console.WriteLine("1) {0}", [String].Concat(o))
      Console.WriteLine("2) {0}", [String].Concat(o, o))
      Console.WriteLine("3) {0}", [String].Concat(o, o, o))
      
      Console.WriteLine(vbCrLf & "Concatenate 4 objects and a variable length parameter list:")
      Console.WriteLine("4) {0}", [String].Concat(o, o, o, o, o))
      
      Console.WriteLine(vbCrLf & "Concatenate a 3 element object array:")
      Console.WriteLine("5) {0}", [String].Concat(objs))
   End Sub 'Main
End Class 'stringConcat5
'
'This example produces the following output:
'Concatenate 1, 2, and 3 objects:
'1) -123
'2) -123-123
'3) -123-123-123
'
'Concatenate 4 objects and a variable length parameter list:
'4) -123-123-123-123-123
'
'Concatenate a 3 element object array:
'5) -123-456-789
'

[C#] 
using System;

class stringConcat5 {
    public static void Main() {
    int i = -123;
    Object o = i;
    Object[] objs = new Object[] {-123, -456, -789};

    Console.WriteLine("Concatenate 1, 2, and 3 objects:");
    Console.WriteLine("1) {0}", String.Concat(o));
    Console.WriteLine("2) {0}", String.Concat(o, o));
    Console.WriteLine("3) {0}", String.Concat(o, o, o));

    Console.WriteLine("\nConcatenate 4 objects and a variable length parameter list:");
    Console.WriteLine("4) {0}", String.Concat(o, o, o, o, o));

    Console.WriteLine("\nConcatenate a 3 element object array:");
    Console.WriteLine("5) {0}", String.Concat(objs));
    }
}
/*
This example produces the following output:
Concatenate 1, 2, and 3 objects:
1) -123
2) -123-123
3) -123-123-123

Concatenate 4 objects and a variable length parameter list:
4) -123-123-123-123-123

Concatenate a 3 element object array:
5) -123-456-789
*/

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

using namespace System;

void main() {
   int i = -123;
   Object* o = __box(i);
   Object* objs[] = {__box(-123), __box(-456), __box(-789)};

   Console::WriteLine(S"Concatenate 1, 2, and 3 objects:");
   Console::WriteLine(S"1) {0}", String::Concat(o));
   Console::WriteLine(S"2) {0}", String::Concat(o, o));
   Console::WriteLine(S"3) {0}", String::Concat(o, o, o));

   Console::WriteLine(S"\nConcatenate 4 objects and a variable length parameter list:");
   Console::WriteLine(S"4) {0}", String::Concat(o, o, o, o, o));

   Console::WriteLine(S"\nConcatenate a 3 element Object* array:");
   Console::WriteLine(S"5) {0}", String::Concat(objs));
}
/*
This example produces the following output:
Concatenate 1, 2, and 3 objects:
1) -123
2) -123-123
3) -123-123-123

Concatenate 4 objects and a variable length parameter list:
4) -123-123-123-123-123

Concatenate a 3 element Object* array:
5) -123-456-789
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

String Class | String Members | System Namespace