String.Concat Method (array<Object>[]()[])

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

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

Syntax

Public Shared Function Concat ( _
    ParamArray args As Object() _
) As String
public static string Concat(
    params Object[] args
)

Parameters

  • args
    Type: array<System..::.Object>[]()[]
    An object array that contains the elements to concatenate.

Return Value

Type: System..::.String
The concatenated string representations of the values of the elements in args.

Exceptions

Exception Condition
ArgumentNullException

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

OutOfMemoryException

Out of memory.

Remarks

The method concatenates each object in argsby calling the parameterless ToString method of that object; it does not add any delimiters.

String..::.Empty is used in place of any null object in the array.

Examples

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




Public Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      ' Create a group of objects.
      Dim t1 As New Test1()
      Dim t2 As New Test2()
      Dim i As Integer = 16
      Dim s As String = "Demonstration"

      ' Place the objects in an array.
      Dim o As Object() = {t1, i, t2, s}


      ' Concatenate the objects together as a string. To do this,
      ' the ToString method of each of the objects is called.
      outputBlock.Text &= String.Concat(o) & vbCrLf
   End Sub 
End Class

' Create two empty test classes.
Class Test1
End Class 

Class Test2
End Class 
' The example displays the following output:
'       Test116Test2Demonstration
using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // 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 of each of the objects is called.
      outputBlock.Text += string.Concat(o) + "\n";
   }
}

// Create two empty test classes.
class Test1
{
}

class Test2
{
}
// The example displays the following output:
//      Test116Test2Demonstration

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

See Also

Reference

String Class

Concat Overload

System Namespace

Object

Join