String.Concat方法

连接指定 Object 数组中的元素的字符串表示形式。

命名空间:                   System
程序集:         mscorlib(位于 mscorlib.dll)


语法:

public static string Concat(	params object[] args
)
)

                       

参数
  • args

  • Type:    System.Object[]

    一个对象数组,其中包含要连接的元素。

返回值

Type:    System.String

 args 中元素的值的串联字符串表示形式。

异常

ExceptionCondition
ArgumentNullException

 argsnull

OutOfMemoryException

内存不足。

备注

The method concatenates each object in args by 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.

调用函数说明:

This method is not called by C++ code. The C++ compiler resolves calls to Overload:System.String.Concat that have four or more object parameters as a call to M:System.String.Concat(System.Object,System.Object,System.Object,System.Object).

示例

The following example demonstrates the use of the M:System.String.Concat(System.Object) method with an T:System.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 of each of the objects is called.
        Console.WriteLine(string.Concat(o));
    }
}
// Create two empty test classes.class Test1 {
}
class Test2 {
}
// The example displays the following output:
// Test116Test2Demonstration


备注:转自https://msdn.microsoft.com/zh-cn/library/k9c94ey1(v=vs.110).aspx