Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

String.Concat Method (Object[])

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

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static string Concat (
	params Object[] args
)
public static String Concat (
	Object[] args
)
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.
Exception typeCondition

ArgumentNullException

args is a null reference (Nothing in Visual Basic).

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

The following code example demonstrates the use of the Concat method with an Object array.

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 {
}

import System.*;

public class ConcatTest
{
    public static void main(String[] args)
    {
        // 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, (Int32)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));
    } //main
} //ConcatTest

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

class Test2
{
} //Test2

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.