Skip to main content
.NET Framework Class Library
StringConcat Method (Object, Object, Object, Object, ...)

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

This API is not CLS-compliant. The CLS-compliant alternative is Concat.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)
Syntax
Visual Basic does not support methods that use variable length arguments (varargs).
The compiler automatically resolves calls to this method to the same method that uses a parameter array.
C# does not support methods that use variable length arguments (varargs).
The compiler automatically resolves calls to this method to the same method that uses a parameter array.
[[%$TOPIC/4ewx19dc_en-us_VS_110_2_0_2_0_0%](false)]
public:
static [%$TOPIC/4ewx19dc_en-us_VS_110_2_0_2_0_1%]^ Concat(
	[%$TOPIC/4ewx19dc_en-us_VS_110_2_0_2_0_2%]^ arg0, 
	[%$TOPIC/4ewx19dc_en-us_VS_110_2_0_2_0_3%]^ arg1, 
	[%$TOPIC/4ewx19dc_en-us_VS_110_2_0_2_0_4%]^ arg2, 
	[%$TOPIC/4ewx19dc_en-us_VS_110_2_0_2_0_5%]^ arg3, 
	...
)
F# does not support methods that use variable length arguments (varargs).
The compiler automatically resolves calls to this method to the same method that uses a parameter array.

Parameters

arg0
Type: SystemObject

The first object to concatenate.

arg1
Type: SystemObject

The second object to concatenate.

arg2
Type: SystemObject

The third object to concatenate.

arg3
Type: SystemObject

The fourth object to concatenate.

Return Value

Type: SystemString
The concatenated string representation of each value in the parameter list.
Remarks

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

StringEmpty is used in place of any null argument.

NoteNote

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).

Examples

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.

Imports System.Collections

Module Example
   Public Sub Main()
      Const WORD_SIZE As Integer = 4

      ' Define some 4-letter words to be scrambled. 
      Dim words() As String = { "home", "food", "game", "rest" }
      ' Define two arrays equal to the number of letters in each word. 
      Dim keys(WORD_SIZE) As Double 
      Dim letters(WORD_SIZE) As String 
      ' Initialize the random number generator. 
      Dim rnd As New Random()

      ' Scramble each word. 
      For Each word As String In words
         For ctr As Integer = 0 To word.Length - 1
            ' Populate the array of keys with random numbers.
            keys(ctr) = rnd.NextDouble()
            ' Assign a letter to the array of letters.
            letters(ctr) = word.Chars(ctr)
         Next    
         ' Sort the array. 
         Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default)      
         ' Display the scrambled word. 
         Dim scrambledWord As String = String.Concat(letters(0), letters(1), _
                                                     letters(2), letters(3))
         Console.WriteLine("{0} --> {1}", word, scrambledWord)
      Next  
   End Sub 
End Module  
' The example displays output like the following: 
'       home --> mheo 
'       food --> oodf 
'       game --> aemg 
'       rest --> trse
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
Version Information

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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