Concat Method (Object, Object, Object, Object, ...)

String.Concat Method (Object, Object, Object, Object)


Concatenates the string representations of four specified objects and any objects specified in an optional variable length parameter list.

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

C# does not support methods that use variable length arguments (varargs).\nThe compiler automatically resolves calls to this method to the same method that uses a\n parameter array.


Type: System.Object

The first object to concatenate.

Type: System.Object

The second object to concatenate.

Type: System.Object

The third object to concatenate.

Type: System.Object

The fourth object to concatenate.

An optional comma-delimited list of one or more additional objects to concatenate.

Return Value

Type: System.String

The concatenated string representation of each value in the parameter list.

The method concatenates each object in the parameter list by calling its parameterless ToString method; it does not add any delimiters.

String.Empty is used in place of any null argument.


The last parameter of the Concat method is an optional comma-delimited list of one or more additional objects to concatenate.

Notes to Callers:

This method is marked with the vararg keyword, which means that it supports a variable number of parameters. The method can be called from Visual C++, but it cannot be called from C# or Visual Basic code. The C# and Visual Basic compilers resolve calls to Concat(Object, Object, Object, Object) as calls to Concat(Object[]).

The following example illustrates the use of the Concat(Object, Object, Object, Object) method to concatenate a list of variable parameters. In this case, the method is called with nine parameters.

using System;
using System.Collections;

public class Example
   public static void Main()
      const int WORD_SIZE = 4;

      // Define some 4-letter words to be scrambled.
      string[] words = { "home", "food", "game", "rest" };
      // Define two arrays equal to the number of letters in each word.
      double[] keys = new double[WORD_SIZE];
      string[] letters = new string[WORD_SIZE];
      // Initialize the random number generator.
      Random rnd = new Random();

      // Scramble each word.
      foreach (string word in words)
         for (int ctr = 0; ctr < word.Length; ctr++)
            // Populate the array of keys with random numbers.
            keys[ctr] = rnd.NextDouble();
            // Assign a letter to the array of letters.
            letters[ctr] = word[ctr].ToString();
         // Sort the array. 
         Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default);      
         // Display the scrambled word.
         string scrambledWord = String.Concat(letters[0], letters[1], 
                                              letters[2], letters[3]);
         Console.WriteLine("{0} --> {1}", word, scrambledWord);
// The example displays output like the following:
//       home --> mheo
//       food --> oodf
//       game --> aemg
//       rest --> trse
Return to top
© 2015 Microsoft