共用方式為


String.Concat Method (array<Object[])

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Updated: October 2010

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

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

Syntax

'Declaration
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 nulla 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

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Change History

Date

History

Reason

October 2010

Revised the Remarks section.

Customer feedback.