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.

This API is not CLS-compliant.

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

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.

Parameters

arg0
Type: System.Object

The first object to concatenate.

arg1
Type: System.Object

The second object to concatenate.

arg2
Type: System.Object

The third object to concatenate.

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

System_CAPS_noteNote

This API is not CLS-compliant. The CLS-compliant alternative is String.Concat(Object()). The C# and Visual Basic compilers automatically resolve a call to this method as a call to String.Concat(Object()).

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.

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

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
Return to top
Show: