Export (0) Print
Expand All

String.Concat Method (Object, Object)

.NET Framework 1.1

Concatenates the String representations of two specified objects.

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

Parameters

arg0
The first Object.
arg1
The second Object.

Return Value

The concatenated String representations of the values of arg0 and arg1.

Remarks

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

If either of the arguments is an array reference, the method concatenates a string representing that array, instead of its members (for example, "System.String[]").

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

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 | Object | Join

Show:
© 2014 Microsoft