Export (0) Print
Expand All

String.Concat Method (Object, Object, Object, Object, ...)

.NET Framework 1.1

Concatenates the String representations of three specified objects and a variable-length parameter list.

This method is not CLS-compliant. For more information about CLS compliance, see What is the Common Language Specification.

[C++]
[CLSCompliant(false)]
public: static String* Concat(
 Object* arg0,
 Object* arg1,
 Object* arg2,
 Object* arg3,
   ...
);

[Visual Basic] This method cannot be used in Visual Basic.

[C#] This method cannot be used in C#.

[JScript] This method cannot be used in JScript.

Parameters [C++]

arg0
The first Object.
arg1
The second Object.
arg2
The third Object.
arg3
The fourth Object.

Return Value [C++]

The concatenated String representations of the values of arg0, arg1, arg2, arg3, and zero or more objects specified in a variable-length parameter list.

Remarks [C++]

Additional arguments can be included in a variable-length parameter list.

An Empty string is used in place of any null argument.

Example

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

[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;

int 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.

Requirements [C++]

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

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

Show:
© 2014 Microsoft