Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

String.Concat Method (Object[])

.NET Framework 1.1

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

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

Parameters

args
An Object array.

Return Value

The concatenated String representations of the values of the elements in args.

Exceptions

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

Remarks

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

Example

[Visual Basic, C#, C++] The following code example demonstrates the use of the Concat method with an Object array.

[Visual Basic] 
Imports System



Public Class ConcatTest
    
    Public Shared Sub Main()
        Dim t1 As New Test1()
        Dim t2 As New Test2()
        Dim i As Integer = 16
        Dim s As String = "Demonstration"
        Dim o As Object() = {t1, i, t2, s}
        
        ' create a group of objects
        
        ' place the objects in an array
        
        ' concatenate the objects together as a string. To do this,
        ' the ToString method in the objects is called
        Console.WriteLine(String.Concat(o))
    End Sub 'Main
End Class 'ConcatTest


' imagine these test classes are full-fledged objects...
Class Test1
End Class 'Test1

Class Test2
End Class 'Test2

[C#] 
using System;

public class ConcatTest {
    public static void Main() {

        // create a group of objects
        Test1 t1 = new Test1();
        Test2 t2 = new Test2();
        int i = 16;
        string s = "Demonstration";

        // place the objects in an array
        object [] o = { t1, i, t2, s };

        // concatenate the objects together as a string. To do this,
        // the ToString method in the objects is called
        Console.WriteLine(string.Concat(o));
    }
}

// imagine these test classes are full-fledged objects...
class Test1 {
}

class Test2 {
}

[C++] 
#using <mscorlib.dll>
using namespace System;

// imagine these test classes are full-fledged objects...
__gc class Test1 {
};

__gc class Test2 {
};

int main() {

        // create a group of objects
        Test1* t1 = new Test1();
        Test2* t2 = new Test2();
        int i = 16;
        String* s = S"Demonstration";

        // place the objects in an array
        Object* o[] = { t1, __box(i), t2, s };

        // concatenate the objects together as a string. To do this,
        // the ToString method in the objects is called
        Console::WriteLine(String::Concat(o));
}

[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:
© 2015 Microsoft