String.Concat String.Concat String.Concat String.Concat Method

Definição

Concatena uma ou mais instâncias de String ou as representações String dos valores de uma ou mais instâncias de Object.Concatenates one or more instances of String, or the String representations of the values of one or more instances of Object.

Sobrecargas

Concat(String, String, String, String) Concat(String, String, String, String) Concat(String, String, String, String) Concat(String, String, String, String)

Concatena quatro instâncias especificadas de String.Concatenates four specified instances of String.

Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>)

Concatena as representações de cadeia de caracteres de quatro intervalos de caracteres somente leitura especificados.Concatenates the string representations of four specified read-only character spans.

Concat(Object, Object, Object, Object) Concat(Object, Object, Object, Object) Concat(Object, Object, Object, Object) Concat(Object, Object, Object, Object)

Concatena as representações de cadeia de caracteres de quatro objetos especificados e quaisquer objetos especificados em uma lista de parâmetros opcionais de tamanho variável.Concatenates the string representations of four specified objects and any objects specified in an optional variable length parameter list.

Concat(String, String, String) Concat(String, String, String) Concat(String, String, String) Concat(String, String, String)

Concatena três instâncias especificadas de String.Concatenates three specified instances of String.

Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>)

Concatena as representações de cadeia de caracteres de três intervalos de caracteres somente leitura especificados.Concatenates the string representations of three specified read-only character spans.

Concat(Object, Object, Object) Concat(Object, Object, Object) Concat(Object, Object, Object) Concat(Object, Object, Object)

Concatena as representações de cadeia de caracteres de três objetos especificados.Concatenates the string representations of three specified objects.

Concat(Object, Object) Concat(Object, Object) Concat(Object, Object) Concat(Object, Object)

Concatena as representações de cadeia de caracteres de dois objetos especificados.Concatenates the string representations of two specified objects.

Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>)

Concatena as representações de cadeia de caracteres de dois intervalos de caracteres somente leitura especificados.Concatenates the string representations of two specified read-only character spans.

Concat(String[]) Concat(String[]) Concat(String[]) Concat(String[])

Concatena os elementos de uma matriz String especificada.Concatenates the elements of a specified String array.

Concat(Object[]) Concat(Object[]) Concat(Object[]) Concat(Object[])

Concatena as representações de cadeia de caracteres dos elementos em uma matriz Object especificada.Concatenates the string representations of the elements in a specified Object array.

Concat(Object) Concat(Object) Concat(Object) Concat(Object)

Cria a representação de cadeia de caracteres de um objeto especificado.Creates the string representation of a specified object.

Concat(IEnumerable<String>) Concat(IEnumerable<String>) Concat(IEnumerable<String>) Concat(IEnumerable<String>)

Concatena os membros de uma coleção de IEnumerable<T> construída do tipo String.Concatenates the members of a constructed IEnumerable<T> collection of type String.

Concat(String, String) Concat(String, String) Concat(String, String) Concat(String, String)

Concatena duas instâncias especificadas de String.Concatenates two specified instances of String.

Concat<T>(IEnumerable<T>) Concat<T>(IEnumerable<T>) Concat<T>(IEnumerable<T>) Concat<T>(IEnumerable<T>)

Concatena os membros de uma implementação IEnumerable<T>.Concatenates the members of an IEnumerable<T> implementation.

Comentários

Observação

Você também pode usar o operador de concatenação de cadeia de caracteres de + seu C#idioma, & como + em, ou e em Visual Basic, para concatenar as cadeias.You can also use your language's string concatenation operator, such as + in C#, or & and + in Visual Basic, to concatenate strings. Ambos os compiladores convertem o operador de concatenação em uma chamada para uma das sobrecargas de String.Concat.Both compilers translate the concatenation operator into a call to one of the overloads of String.Concat.

Concat(String, String, String, String) Concat(String, String, String, String) Concat(String, String, String, String) Concat(String, String, String, String)

Concatena quatro instâncias especificadas de String.Concatenates four specified instances of String.

public:
 static System::String ^ Concat(System::String ^ str0, System::String ^ str1, System::String ^ str2, System::String ^ str3);
public static string Concat (string str0, string str1, string str2, string str3);
static member Concat : string * string * string * string -> string
Public Shared Function Concat (str0 As String, str1 As String, str2 As String, str3 As String) As String

Parâmetros

str0
String String String String

A primeira sequência de caracteres a ser concatenada.The first string to concatenate.

str1
String String String String

A segunda sequência de caracteres a ser concatenada.The second string to concatenate.

str2
String String String String

A terceira cadeia de caracteres a ser concatenada.The third string to concatenate.

str3
String String String String

A quarta cadeia de caracteres a ser concatenada.The fourth string to concatenate.

Retornos

A concatenação de str0, str1, str2 e str3.The concatenation of str0, str1, str2, and str3.

Exemplos

O exemplo a seguir define uma matriz de palavras de quatro letras e armazena suas letras individuais para uma matriz de cadeia de caracteres a fim de embaralha-las.The following example defines an array of four-letter words and stores their individual letters to a string array in order to scramble them. Em seguida, ele Concat(String, String, String, String) chama o método para remontar as palavras embaralhadas.It then calls the Concat(String, String, String, String) method to reassemble the scrambled words.

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

Comentários

O método concatena str0, str1, str2e str3; ele não adiciona nenhum delimitador.The method concatenates str0, str1, str2, and str3; it does not add any delimiters.

Veja também

Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>)

Concatena as representações de cadeia de caracteres de quatro intervalos de caracteres somente leitura especificados.Concatenates the string representations of four specified read-only character spans.

public:
 static System::String ^ Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2, ReadOnlySpan<char> str3);
public static string Concat (ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2, ReadOnlySpan<char> str3);
static member Concat : ReadOnlySpan<char> * ReadOnlySpan<char> * ReadOnlySpan<char> * ReadOnlySpan<char> -> string
Public Shared Function Concat (str0 As ReadOnlySpan(Of Char), str1 As ReadOnlySpan(Of Char), str2 As ReadOnlySpan(Of Char), str3 As ReadOnlySpan(Of Char)) As String

Parâmetros

str0
ReadOnlySpan<Char>

O primeiro intervalo de caracteres somente leitura a ser concatenado.The first read-only character span to concatenate.

str1
ReadOnlySpan<Char>

O segundo intervalo de caracteres somente leitura a ser concatenado.The second read-only character span to concatenate.

str2
ReadOnlySpan<Char>

O terceiro intervalo de caracteres somente leitura a ser concatenado.The third read-only character span to concatenate.

str3
ReadOnlySpan<Char>

O quarto intervalo de caracteres somente leitura a ser concatenado.The fourth read-only character span to concatenate.

Retornos

As representações de cadeia de caracteres concatenadas dos valores de str0, str1, str2 e str3.The concatenated string representations of the values of str0, str1, str2 and str3.

Concat(Object, Object, Object, Object) Concat(Object, Object, Object, Object) Concat(Object, Object, Object, Object) Concat(Object, Object, Object, Object)

Importante

Esta API não está em conformidade com CLS.

Concatena as representações de cadeia de caracteres de quatro objetos especificados e quaisquer objetos especificados em uma lista de parâmetros opcionais de tamanho variável.Concatenates the string representations of four specified objects and any objects specified in an optional variable length parameter list.

public:
 static System::String ^ Concat(System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2, System::Object ^ arg3);
[System.CLSCompliant(false)]
public static string Concat (object arg0, object arg1, object arg2, object arg3);
static member Concat : obj * obj * obj * obj -> string
Public Shared Function Concat (arg0 As Object, arg1 As Object, arg2 As Object, arg3 As Object) As String

Parâmetros

arg0
Object Object Object Object

O primeiro objeto a ser concatenado.The first object to concatenate.

arg1
Object Object Object Object

O segundo objeto a ser concatenado.The second object to concatenate.

arg2
Object Object Object Object

O terceiro objeto a ser concatenado.The third object to concatenate.

arg3
Object Object Object Object

O quarto objeto a ser concatenado.The fourth object to concatenate.

Retornos

A representação de cadeia de caracteres concatenada de cada valor na lista de parâmetros.The concatenated string representation of each value in the parameter list.

Exemplos

O exemplo a seguir ilustra o uso do Concat(Object, Object, Object, Object) método para concatenar uma lista de parâmetros de variáveis.The following example illustrates the use of the Concat(Object, Object, Object, Object) method to concatenate a list of variable parameters. Nesse caso, o método é chamado com nove parâmetros.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
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

Comentários

Observação

Esta API não compatível com CLS.This API is not CLS-compliant. A alternativa compatível com CLS é String.Concat(Object[]).The CLS-compliant alternative is String.Concat(Object[]). Os C# compiladores e Visual Basic resolvem automaticamente uma chamada para esse método como uma chamada String.Concat(Object[])para.The C# and Visual Basic compilers automatically resolve a call to this method as a call to String.Concat(Object[]).

O método concatena cada objeto na lista de parâmetros chamando seu ToString método sem parâmetros; ele não adiciona nenhum delimitador.The method concatenates each object in the parameter list by calling its parameterless ToString method; it does not add any delimiters.

String.Emptyé usado no lugar de qualquer argumento nulo.String.Empty is used in place of any null argument.

Observação

O último parâmetro do Concat método é uma lista opcional delimitada por vírgulas de um ou mais objetos adicionais para concatenar.The last parameter of the Concat method is an optional comma-delimited list of one or more additional objects to concatenate.

Notas aos Chamadores

Esse método é marcado com a vararg palavra-chave, o que significa que ele dá suporte a um número variável de parâmetros.This method is marked with the vararg keyword, which means that it supports a variable number of parameters. O método pode ser chamado do Visual C++, mas não pode ser chamado a C# partir de ou Visual Basic código.The method can be called from Visual C++, but it cannot be called from C# or Visual Basic code. Os C# compiladores e Visual Basic resolvem chamadas Concat(Object, Object, Object, Object) como chamadas para Concat(Object[]).The C# and Visual Basic compilers resolve calls to Concat(Object, Object, Object, Object) as calls to Concat(Object[]).

Concat(String, String, String) Concat(String, String, String) Concat(String, String, String) Concat(String, String, String)

Concatena três instâncias especificadas de String.Concatenates three specified instances of String.

public:
 static System::String ^ Concat(System::String ^ str0, System::String ^ str1, System::String ^ str2);
public static string Concat (string str0, string str1, string str2);
static member Concat : string * string * string -> string
Public Shared Function Concat (str0 As String, str1 As String, str2 As String) As String

Parâmetros

str0
String String String String

A primeira sequência de caracteres a ser concatenada.The first string to concatenate.

str1
String String String String

A segunda sequência de caracteres a ser concatenada.The second string to concatenate.

str2
String String String String

A terceira cadeia de caracteres a ser concatenada.The third string to concatenate.

Retornos

A concatenação de str0, str1 e str2.The concatenation of str0, str1, and str2.

Exemplos

O exemplo a seguir usa Concat o método para concatenar três cadeias de caracteres e exibe o resultado.The following example uses the Concat method to concatenate three strings and displays the result.

using namespace System;

void main()
{
   String^ s1 = "We went to a bookstore, ";
   String^ s2 = "a movie, ";
   String^ s3 = "and a restaurant.";

   String^ s = String::Concat(s1, s2, s3);
   Console::WriteLine(s);
}
// The example displays the following output:
//      We went to a bookstore, a movie, and a restaurant. 
using System;

public class Example
{
   public static void Main()
   {
      String s1 = "We went to a bookstore, ";
      String s2 = "a movie, ";
      String s3 = "and a restaurant.";

      var s = String.Concat(s1, s2, s3);
      Console.WriteLine(s);
   }
}
// The example displays the following output:
//      We went to a bookstore, a movie, and a restaurant. 
Imports System

Public Module Example
   Public Sub Main()
      Dim s1 As String = "We went to a bookstore, "
      Dim s2 As String = "a movie, "
      Dim s3 As String = "and a restaurant."

      Dim s = String.Concat(s1, s2, s3)
      Console.WriteLine(s)
   End Sub
End Module
' The example displays the following output:
'      We went to a bookstore, a movie, and a restaurant. 

Comentários

O método concatena str0, str1e str2; ele não adiciona nenhum delimitador.The method concatenates str0, str1, and str2; it does not add any delimiters.

Veja também

Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>)

Concatena as representações de cadeia de caracteres de três intervalos de caracteres somente leitura especificados.Concatenates the string representations of three specified read-only character spans.

public:
 static System::String ^ Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2);
public static string Concat (ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2);
static member Concat : ReadOnlySpan<char> * ReadOnlySpan<char> * ReadOnlySpan<char> -> string
Public Shared Function Concat (str0 As ReadOnlySpan(Of Char), str1 As ReadOnlySpan(Of Char), str2 As ReadOnlySpan(Of Char)) As String

Parâmetros

str0
ReadOnlySpan<Char>

O primeiro intervalo de caracteres somente leitura a ser concatenado.The first read-only character span to concatenate.

str1
ReadOnlySpan<Char>

O segundo intervalo de caracteres somente leitura a ser concatenado.The second read-only character span to concatenate.

str2
ReadOnlySpan<Char>

O terceiro intervalo de caracteres somente leitura a ser concatenado.The third read-only character span to concatenate.

Retornos

As representações de cadeia de caracteres concatenadas dos valores de str0, str1 e str2.The concatenated string representations of the values of str0, str1 and str2.

Concat(Object, Object, Object) Concat(Object, Object, Object) Concat(Object, Object, Object) Concat(Object, Object, Object)

Concatena as representações de cadeia de caracteres de três objetos especificados.Concatenates the string representations of three specified objects.

public:
 static System::String ^ Concat(System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2);
public static string Concat (object arg0, object arg1, object arg2);
static member Concat : obj * obj * obj -> string
Public Shared Function Concat (arg0 As Object, arg1 As Object, arg2 As Object) As String

Parâmetros

arg0
Object Object Object Object

O primeiro objeto a ser concatenado.The first object to concatenate.

arg1
Object Object Object Object

O segundo objeto a ser concatenado.The second object to concatenate.

arg2
Object Object Object Object

O terceiro objeto a ser concatenado.The third object to concatenate.

Retornos

As representações de cadeia de caracteres concatenadas dos valores de arg0, arg1 e arg2.The concatenated string representations of the values of arg0, arg1, and arg2.

Exemplos

O exemplo a seguir demonstra Concat o método.The following example demonstrates the Concat method.

using namespace System;

int main()
{
   int i = -123;
   Object^ o = i;
   array<Object^>^objs = { -123, -456, -789};
   Console::WriteLine("Concatenate 1, 2, and 3 objects:");
   Console::WriteLine("1) {0}", String::Concat(o));
   Console::WriteLine("2) {0}", String::Concat(o, o));
   Console::WriteLine("3) {0}", String::Concat(o, o, o));
   
   Console::WriteLine("\nConcatenate 4 objects and a variable length parameter list:" );
   Console::WriteLine("4) {0}", String::Concat(o, o, o, o));
   Console::WriteLine("5) {0}", String::Concat( o, o, o, o, o));
   Console::WriteLine("\nConcatenate a 3-element object array:");
   Console::WriteLine("6) {0}", String::Concat(objs));
}
// The example displays the following output:
//    Concatenate 1, 2, and 3 objects:
//    1) -123
//    2) -123-123
//    3) -123-123-123
//    
//    Concatenate 4 objects and a variable length parameter list:
//    4) -123-123-123-123
//    5) -123-123-123-123-123
//    
//    Concatenate a 3-element object array:
//    6) -123-456-789
using System;

class stringConcat5 {
    public static void Main() {
    int i = -123;
    Object o = i;
    Object[] objs = new Object[] {-123, -456, -789};

    Console.WriteLine("Concatenate 1, 2, and 3 objects:");
    Console.WriteLine("1) {0}", String.Concat(o));
    Console.WriteLine("2) {0}", String.Concat(o, o));
    Console.WriteLine("3) {0}", String.Concat(o, o, o));

    Console.WriteLine("\nConcatenate 4 objects and a variable length parameter list:");
    Console.WriteLine("4) {0}", String.Concat(o, o, o, o));
    Console.WriteLine("5) {0}", String.Concat(o, o, o, o, o));

    Console.WriteLine("\nConcatenate a 3-element object array:");
    Console.WriteLine("6) {0}", String.Concat(objs));
    }
}
// The example displays the following output:
//    Concatenate 1, 2, and 3 objects:
//    1) -123
//    2) -123-123
//    3) -123-123-123
//    
//    Concatenate 4 objects and a variable length parameter list:
//    4) -123-123-123-123
//    5) -123-123-123-123-123
//    
//    Concatenate a 3-element object array:
//    6) -123-456-789
Class stringConcat5
   Public Shared Sub Main()
      Dim i As Integer = - 123
      Dim o As [Object] = i
      Dim objs() As [Object] = {-123, -456, -789}
      
      Console.WriteLine("Concatenate 1, 2, and 3 objects:")
      Console.WriteLine("1) {0}", [String].Concat(o))
      Console.WriteLine("2) {0}", [String].Concat(o, o))
      Console.WriteLine("3) {0}", [String].Concat(o, o, o))
      
      Console.WriteLine(vbCrLf & "Concatenate 4 objects and a variable length parameter list:")
      Console.WriteLine("4) {0}", String.Concat(o, o, o, o))
      Console.WriteLine("5) {0}", String.Concat(o, o, o, o, o))
      
      Console.WriteLine(vbCrLf & "Concatenate a 3-element object array:")
      Console.WriteLine("6) {0}", [String].Concat(objs))
   End Sub
End Class
'The example displays the following output:
'    Concatenate 1, 2, and 3 objects:
'    1) -123
'    2) -123-123
'    3) -123-123-123
'    
'    Concatenate 4 objects and a variable length parameter list:
'    4) -123-123-123-123
'    5) -123-123-123-123-123
'         
'    Concatenate a 3-element object array:
'    6) -123-456-789

Comentários

O método concatena arg0, arg1e arg2 chamando o ToString método sem parâmetros de cada objeto; ele não adiciona nenhum delimitador.The method concatenates arg0, arg1, and arg2 by calling the parameterless ToString method of each object; it does not add any delimiters.

String.Emptyé usado no lugar de qualquer argumento nulo.String.Empty is used in place of any null argument.

Veja também

Concat(Object, Object) Concat(Object, Object) Concat(Object, Object) Concat(Object, Object)

Concatena as representações de cadeia de caracteres de dois objetos especificados.Concatenates the string representations of two specified objects.

public:
 static System::String ^ Concat(System::Object ^ arg0, System::Object ^ arg1);
public static string Concat (object arg0, object arg1);
static member Concat : obj * obj -> string
Public Shared Function Concat (arg0 As Object, arg1 As Object) As String

Parâmetros

arg0
Object Object Object Object

O primeiro objeto a ser concatenado.The first object to concatenate.

arg1
Object Object Object Object

O segundo objeto a ser concatenado.The second object to concatenate.

Retornos

As representações de cadeia de caracteres concatenadas dos valores de arg0 e arg1.The concatenated string representations of the values of arg0 and arg1.

Exemplos

O exemplo a seguir demonstra Concat o método.The following example demonstrates the Concat method.

using namespace System;

int main()
{
   int i = -123;
   Object^ o = i;
   array<Object^>^objs = { -123, -456, -789};
   Console::WriteLine("Concatenate 1, 2, and 3 objects:");
   Console::WriteLine("1) {0}", String::Concat(o));
   Console::WriteLine("2) {0}", String::Concat(o, o));
   Console::WriteLine("3) {0}", String::Concat(o, o, o));
   
   Console::WriteLine("\nConcatenate 4 objects and a variable length parameter list:" );
   Console::WriteLine("4) {0}", String::Concat(o, o, o, o));
   Console::WriteLine("5) {0}", String::Concat( o, o, o, o, o));
   Console::WriteLine("\nConcatenate a 3-element object array:");
   Console::WriteLine("6) {0}", String::Concat(objs));
}
// The example displays the following output:
//    Concatenate 1, 2, and 3 objects:
//    1) -123
//    2) -123-123
//    3) -123-123-123
//    
//    Concatenate 4 objects and a variable length parameter list:
//    4) -123-123-123-123
//    5) -123-123-123-123-123
//    
//    Concatenate a 3-element object array:
//    6) -123-456-789
using System;

class stringConcat5 {
    public static void Main() {
    int i = -123;
    Object o = i;
    Object[] objs = new Object[] {-123, -456, -789};

    Console.WriteLine("Concatenate 1, 2, and 3 objects:");
    Console.WriteLine("1) {0}", String.Concat(o));
    Console.WriteLine("2) {0}", String.Concat(o, o));
    Console.WriteLine("3) {0}", String.Concat(o, o, o));

    Console.WriteLine("\nConcatenate 4 objects and a variable length parameter list:");
    Console.WriteLine("4) {0}", String.Concat(o, o, o, o));
    Console.WriteLine("5) {0}", String.Concat(o, o, o, o, o));

    Console.WriteLine("\nConcatenate a 3-element object array:");
    Console.WriteLine("6) {0}", String.Concat(objs));
    }
}
// The example displays the following output:
//    Concatenate 1, 2, and 3 objects:
//    1) -123
//    2) -123-123
//    3) -123-123-123
//    
//    Concatenate 4 objects and a variable length parameter list:
//    4) -123-123-123-123
//    5) -123-123-123-123-123
//    
//    Concatenate a 3-element object array:
//    6) -123-456-789
Class stringConcat5
   Public Shared Sub Main()
      Dim i As Integer = - 123
      Dim o As [Object] = i
      Dim objs() As [Object] = {-123, -456, -789}
      
      Console.WriteLine("Concatenate 1, 2, and 3 objects:")
      Console.WriteLine("1) {0}", [String].Concat(o))
      Console.WriteLine("2) {0}", [String].Concat(o, o))
      Console.WriteLine("3) {0}", [String].Concat(o, o, o))
      
      Console.WriteLine(vbCrLf & "Concatenate 4 objects and a variable length parameter list:")
      Console.WriteLine("4) {0}", String.Concat(o, o, o, o))
      Console.WriteLine("5) {0}", String.Concat(o, o, o, o, o))
      
      Console.WriteLine(vbCrLf & "Concatenate a 3-element object array:")
      Console.WriteLine("6) {0}", [String].Concat(objs))
   End Sub
End Class
'The example displays the following output:
'    Concatenate 1, 2, and 3 objects:
'    1) -123
'    2) -123-123
'    3) -123-123-123
'    
'    Concatenate 4 objects and a variable length parameter list:
'    4) -123-123-123-123
'    5) -123-123-123-123-123
'         
'    Concatenate a 3-element object array:
'    6) -123-456-789

Comentários

O arg0 método concatena arg1e arg1 chamando o ToString método sem parâmetros de arg0 e; ele não adiciona nenhum delimitador.The method concatenates arg0 and arg1 by calling the parameterless ToString method of arg0 and arg1; it does not add any delimiters.

String.Emptyé usado no lugar de qualquer argumento nulo.String.Empty is used in place of any null argument.

Se qualquer um dos argumentos for uma referência de matriz, o método concatena uma cadeia de caracteres que representa essa matriz, em vez de seus membros (por exemplo, "System. String []").If either of the arguments is an array reference, the method concatenates a string representing that array, instead of its members (for example, "System.String[]").

Veja também

Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>) Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>)

Concatena as representações de cadeia de caracteres de dois intervalos de caracteres somente leitura especificados.Concatenates the string representations of two specified read-only character spans.

public:
 static System::String ^ Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1);
public static string Concat (ReadOnlySpan<char> str0, ReadOnlySpan<char> str1);
static member Concat : ReadOnlySpan<char> * ReadOnlySpan<char> -> string
Public Shared Function Concat (str0 As ReadOnlySpan(Of Char), str1 As ReadOnlySpan(Of Char)) As String

Parâmetros

str0
ReadOnlySpan<Char>

O primeiro intervalo de caracteres somente leitura a ser concatenado.The first read-only character span to concatenate.

str1
ReadOnlySpan<Char>

O segundo intervalo de caracteres somente leitura a ser concatenado.The second read-only character span to concatenate.

Retornos

As representações de cadeia de caracteres concatenadas dos valores de str0 e str1.The concatenated string representations of the values of str0 and str1.

Concat(String[]) Concat(String[]) Concat(String[]) Concat(String[])

Importante

Esta API não está em conformidade com CLS.

Concatena os elementos de uma matriz String especificada.Concatenates the elements of a specified String array.

public:
 static System::String ^ Concat(... cli::array <System::String ^> ^ values);
[System.CLSCompliant(false)]
public static string Concat (params string[] values);
static member Concat : string[] -> string
Public Shared Function Concat (ParamArray values As String()) As String

Parâmetros

values
String[]

Uma matriz de instâncias de cadeia de caracteres.An array of string instances.

Retornos

Os elementos concatenados de values.The concatenated elements of values.

Exceções

Exemplos

O exemplo a seguir demonstra o uso do Concat método com uma String matriz.The following example demonstrates the use of the Concat method with a String array.

using namespace System;

int main()
{
   
   // Make an array of strings. Note that we have included spaces.
   array<String^>^s = { "hello ", "and ", "welcome ", "to ",
                        "this ", "demo! "};
   
   // Put all the strings together.
   Console::WriteLine( String::Concat(s) );
   
   // Sort the strings, and put them together.
   Array::Sort( s );
   Console::WriteLine( String::Concat(s));
}
// The example displays the following output:
//       hello and welcome to this demo!
//       and demo! hello this to welcome
using System;

public class Example
{
    public static void Main()
    {
        // Make an array of strings. Note that we have included spaces.
        string [] s = { "hello ", "and ", "welcome ", "to ",
                        "this ", "demo! " };

        // Put all the strings together.
        Console.WriteLine(string.Concat(s));

        // Sort the strings, and put them together.
        Array.Sort(s);
        Console.WriteLine(string.Concat(s));
    }
}
// The example displays the following output:
//       hello and welcome to this demo!
//       and demo! hello this to welcome
Public Class Example
    Public Shared Sub Main()
        ' Make an array of strings. Note that we have included spaces.
        Dim s As String() = { "hello ", "and ", "welcome ", "to ",
                              "this ", "demo! "}

        ' Put all the strings together.
        Console.WriteLine(String.Concat(s))
        
        ' Sort the strings, and put them together.
        Array.Sort(s)
        Console.WriteLine(String.Concat(s))
    End Sub
End Class
' The example displays the following output:
'       hello and welcome to this demo!
'       and demo! hello this to welcome

Comentários

O método concatena cada objeto no values; ele não adiciona nenhum delimitador.The method concatenates each object in values; it does not add any delimiters.

Uma Empty cadeia de caracteres é usada no lugar de qualquer objeto nulo na matriz.An Empty string is used in place of any null object in the array.

Veja também

Concat(Object[]) Concat(Object[]) Concat(Object[]) Concat(Object[])

Concatena as representações de cadeia de caracteres dos elementos em uma matriz Object especificada.Concatenates the string representations of the elements in a specified Object array.

public:
 static System::String ^ Concat(... cli::array <System::Object ^> ^ args);
public static string Concat (params object[] args);
static member Concat : obj[] -> string
Public Shared Function Concat (ParamArray args As Object()) As String

Parâmetros

args
Object[]

Uma matriz de objeto que contém os elementos a serem concatenados.An object array that contains the elements to concatenate.

Retornos

As representações de cadeia de caracteres concatenadas dos valores dos elementos em args.The concatenated string representations of the values of the elements in args.

Exceções

Exemplos

O exemplo a seguir demonstra o uso do Concat método com uma Object matriz.The following example demonstrates the use of the Concat method with an 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
Imports System



Public Class ConcatTest
    
    Public Shared Sub Main()
        Dim t1 As New Test1()
        Dim t2 As New Test2()
        Dim i As Integer = 16
        Dim s As String = "Demonstration"
        Dim o As Object() = {t1, i, t2, s}
        
        ' create a group of objects
        
        ' place the objects in an array
        
        ' concatenate the objects together as a string. To do this,
        ' the ToString method in the objects is called
        Console.WriteLine(String.Concat(o))
    End Sub 'Main
End Class 'ConcatTest


' imagine these test classes are full-fledged objects...
Class Test1
End Class 'Test1

Class Test2
End Class 'Test2

Comentários

O método concatena cada objeto no args chamando o ToString método sem parâmetros desse objeto; ele não adiciona nenhum delimitador.The method concatenates each object in args by calling the parameterless ToString method of that object; it does not add any delimiters.

String.Emptyé usado no lugar de qualquer objeto nulo na matriz.String.Empty is used in place of any null object in the array.

Notas aos Chamadores

Esse método não é chamado pelo C++ código.This method is not called by C++ code. O C++ compilador resolve chamadas para Concat que têm quatro ou mais parâmetros de objeto como uma chamada para. Concat(Object, Object, Object, Object)The C++ compiler resolves calls to Concat that have four or more object parameters as a call to Concat(Object, Object, Object, Object).

Veja também

Concat(Object) Concat(Object) Concat(Object) Concat(Object)

Cria a representação de cadeia de caracteres de um objeto especificado.Creates the string representation of a specified object.

public:
 static System::String ^ Concat(System::Object ^ arg0);
public static string Concat (object arg0);
static member Concat : obj -> string
Public Shared Function Concat (arg0 As Object) As String

Parâmetros

arg0
Object Object Object Object

O objeto a ser representado ou null.The object to represent, or null.

Retornos

A representação da cadeia de caracteres do valor de arg0 ou Empty se arg0 for null.The string representation of the value of arg0, or Empty if arg0 is null.

Exemplos

O exemplo a seguir demonstra Concat o método.The following example demonstrates the Concat method.

using namespace System;

int main()
{
   int i = -123;
   Object^ o = i;
   array<Object^>^objs = { -123, -456, -789};
   Console::WriteLine("Concatenate 1, 2, and 3 objects:");
   Console::WriteLine("1) {0}", String::Concat(o));
   Console::WriteLine("2) {0}", String::Concat(o, o));
   Console::WriteLine("3) {0}", String::Concat(o, o, o));
   
   Console::WriteLine("\nConcatenate 4 objects and a variable length parameter list:" );
   Console::WriteLine("4) {0}", String::Concat(o, o, o, o));
   Console::WriteLine("5) {0}", String::Concat( o, o, o, o, o));
   Console::WriteLine("\nConcatenate a 3-element object array:");
   Console::WriteLine("6) {0}", String::Concat(objs));
}
// The example displays the following output:
//    Concatenate 1, 2, and 3 objects:
//    1) -123
//    2) -123-123
//    3) -123-123-123
//    
//    Concatenate 4 objects and a variable length parameter list:
//    4) -123-123-123-123
//    5) -123-123-123-123-123
//    
//    Concatenate a 3-element object array:
//    6) -123-456-789
using System;

class stringConcat5 {
    public static void Main() {
    int i = -123;
    Object o = i;
    Object[] objs = new Object[] {-123, -456, -789};

    Console.WriteLine("Concatenate 1, 2, and 3 objects:");
    Console.WriteLine("1) {0}", String.Concat(o));
    Console.WriteLine("2) {0}", String.Concat(o, o));
    Console.WriteLine("3) {0}", String.Concat(o, o, o));

    Console.WriteLine("\nConcatenate 4 objects and a variable length parameter list:");
    Console.WriteLine("4) {0}", String.Concat(o, o, o, o));
    Console.WriteLine("5) {0}", String.Concat(o, o, o, o, o));

    Console.WriteLine("\nConcatenate a 3-element object array:");
    Console.WriteLine("6) {0}", String.Concat(objs));
    }
}
// The example displays the following output:
//    Concatenate 1, 2, and 3 objects:
//    1) -123
//    2) -123-123
//    3) -123-123-123
//    
//    Concatenate 4 objects and a variable length parameter list:
//    4) -123-123-123-123
//    5) -123-123-123-123-123
//    
//    Concatenate a 3-element object array:
//    6) -123-456-789
Class stringConcat5
   Public Shared Sub Main()
      Dim i As Integer = - 123
      Dim o As [Object] = i
      Dim objs() As [Object] = {-123, -456, -789}
      
      Console.WriteLine("Concatenate 1, 2, and 3 objects:")
      Console.WriteLine("1) {0}", [String].Concat(o))
      Console.WriteLine("2) {0}", [String].Concat(o, o))
      Console.WriteLine("3) {0}", [String].Concat(o, o, o))
      
      Console.WriteLine(vbCrLf & "Concatenate 4 objects and a variable length parameter list:")
      Console.WriteLine("4) {0}", String.Concat(o, o, o, o))
      Console.WriteLine("5) {0}", String.Concat(o, o, o, o, o))
      
      Console.WriteLine(vbCrLf & "Concatenate a 3-element object array:")
      Console.WriteLine("6) {0}", [String].Concat(objs))
   End Sub
End Class
'The example displays the following output:
'    Concatenate 1, 2, and 3 objects:
'    1) -123
'    2) -123-123
'    3) -123-123-123
'    
'    Concatenate 4 objects and a variable length parameter list:
'    4) -123-123-123-123
'    5) -123-123-123-123-123
'         
'    Concatenate a 3-element object array:
'    6) -123-456-789

Comentários

O Concat(Object) método representa arg0 como uma cadeia de caracteres chamando seu ToString método sem parâmetros.The Concat(Object) method represents arg0 as a string by calling its parameterless ToString method.

Veja também

Concat(IEnumerable<String>) Concat(IEnumerable<String>) Concat(IEnumerable<String>) Concat(IEnumerable<String>)

Concatena os membros de uma coleção de IEnumerable<T> construída do tipo String.Concatenates the members of a constructed IEnumerable<T> collection of type String.

public:
 static System::String ^ Concat(System::Collections::Generic::IEnumerable<System::String ^> ^ values);
[System.Runtime.InteropServices.ComVisible(false)]
public static string Concat (System.Collections.Generic.IEnumerable<string> values);
static member Concat : seq<string> -> string
Public Shared Function Concat (values As IEnumerable(Of String)) As String

Parâmetros

values
IEnumerable<String>

Um objeto de coleção que implementa IEnumerable<T> e cujo argumento de tipo genérico é String.A collection object that implements IEnumerable<T> and whose generic type argument is String.

Retornos

As cadeias de caracteres concatenadas em values ou Empty se values for um IEnumerable(Of String) vazio.The concatenated strings in values, or Empty if values is an empty IEnumerable(Of String).

Exceções

Exemplos

O exemplo a seguir usa o algoritmo Sieve of Eratosthenes para calcular os números principais menores que ou iguais a 100.The following example uses the Sieve of Eratosthenes algorithm to calculate the prime numbers that are less than or equal to 100. Ele atribui o resultado a um List<T> objeto do tipo String, que passa para o Concat(IEnumerable<String>) método.It assigns the result to a List<T> object of type String, which it then passes to the Concat(IEnumerable<String>) method.

using System;
using System.Collections.Generic;

public class Example
{
   public static void Main()
   {
      int maxPrime = 100;
      IEnumerable<String> primeList = GetPrimes(maxPrime);
      Console.WriteLine("Primes less than {0}:", maxPrime);
      Console.WriteLine("   {0}", String.Concat(primeList));
   }

   private static IEnumerable<String> GetPrimes(int maxPrime)
   {
      Array values = Array.CreateInstance(typeof(int), 
                              new int[] { maxPrime - 1}, new int[] { 2 }); 
      // Use Sieve of Erathsthenes to determine prime numbers.
      for (int ctr = values.GetLowerBound(0); ctr <= (int) Math.Ceiling(Math.Sqrt(values.GetUpperBound(0))); ctr++)
      {
                           
         if ((int) values.GetValue(ctr) == 1) continue;
         
         for (int multiplier = ctr; multiplier <=  maxPrime / 2; multiplier++)
            if (ctr * multiplier <= maxPrime)
               values.SetValue(1, ctr * multiplier);
      }      
      
      List<String> primes = new List<String>();
      for (int ctr = values.GetLowerBound(0); ctr <= values.GetUpperBound(0); ctr++)
         if ((int) values.GetValue(ctr) == 0) 
            primes.Add(ctr.ToString() + " ");
      return primes;
   }   
}
// The example displays the following output:
//    Primes less than 100:
//       2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Imports System.Collections.Generic

Module Example
   Public Sub Main()
      Dim maxPrime As Integer = 100
      Dim primeList As IEnumerable(Of String) = GetPrimes(maxPrime)
      Console.WriteLine("Primes less than {0}:", maxPrime)
      Console.WriteLine("   {0}", String.Concat(primeList))
   End Sub
   
   Private Function GetPrimes(maxPrime As Integer) As IEnumerable(Of String)
      Dim values As Array = Array.CreateInstance(GetType(Integer), _
                              New Integer() { maxPrime - 1}, New Integer(){ 2 }) 
      ' Use Sieve of Erathsthenes to determine prime numbers.
      For ctr As Integer = values.GetLowerBound(0) To _
                           CInt(Math.Ceiling(Math.Sqrt(values.GetUpperBound(0))))
         If CInt(values.GetValue(ctr)) = 1 Then Continue For
         
         For multiplier As Integer = ctr To maxPrime \ 2
            If ctr * multiplier <= maxPrime Then values.SetValue(1, ctr * multiplier)
         Next   
      Next      
      
      Dim primes As New List(Of String)
      For ctr As Integer = values.GetLowerBound(0) To values.GetUpperBound(0)
         If CInt(values.GetValue(ctr)) = 0 Then primes.Add(ctr.ToString() + " ")
      Next            
      Return primes
   End Function   
End Module
' The example displays the following output:
'    Primes less than 100:
'       2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Comentários

O método concatena cada objeto no values; ele não adiciona nenhum delimitador.The method concatenates each object in values; it does not add any delimiters. Para especificar um delimitador entre cada valuesmembro de, Join(String, IEnumerable<String>) chame o método.To specify a delimiter between each member of values, call the Join(String, IEnumerable<String>) method.

Uma Empty cadeia de caracteres é usada no lugar de qualquer elemento valuesnulo no.An Empty string is used in place of any null element in values.

Se values for um IEnumerable(Of String), o método retornará String.Empty.If values is an empty IEnumerable(Of String), the method returns String.Empty. Se values ArgumentNullException for null, o método lançará uma exceção.If values is null, the method throws an ArgumentNullException exception.

Concat(IEnumerable<String>)é um método de conveniência que permite concatenar cada elemento em uma IEnumerable(Of String) coleção sem primeiro converter os elementos em uma matriz de cadeia de caracteres.Concat(IEnumerable<String>) is a convenience method that lets you concatenate each element in an IEnumerable(Of String) collection without first converting the elements to a string array. Ele é particularmente útil com expressões de consulta LINQ (consulta integrada à linguagem).It is particularly useful with Language-Integrated Query (LINQ) query expressions. O exemplo a seguir passa List(Of String) um objeto que contém letras maiúsculas ou minúsculas do alfabeto para uma expressão lambda que seleciona letras iguais ou maiores que uma letra específica (que, no exemplo, é "M").The following example passes a List(Of String) object that contains either the uppercase or lowercase letters of the alphabet to a lambda expression that selects letters that are equal to or greater than a particular letter (which, in the example, is "M"). A IEnumerable(Of String) coleção retornada Enumerable.Where pelo método é passada para o Concat(IEnumerable<String>) método para exibir o resultado como uma única cadeia de caracteres.The IEnumerable(Of String) collection that is returned by the Enumerable.Where method is passed to the Concat(IEnumerable<String>) method to display the result as a single string.

using System;
using System.Collections.Generic;
using System.Linq;

public class Example
{
   public static void Main()
   {
      string output = String.Concat( GetAlphabet(true).Where( letter => 
                      letter.CompareTo("M") >= 0));
      Console.WriteLine(output);  
   }

   private static List<string> GetAlphabet(bool upper)
   {
      List<string> alphabet = new List<string>();
      int charValue = upper ? 65 : 97;
      for (int ctr = 0; ctr <= 25; ctr++)
         alphabet.Add(Convert.ToChar(charValue + ctr).ToString());
      return alphabet; 
   }
}
// The example displays the following output:
//      MNOPQRSTUVWXYZ
Imports System.Collections.Generic
Imports System.Linq

Module modMain
   Public Sub Main()
      Dim output As String = String.Concat(GetAlphabet(true).Where(Function(letter) _
                                                         letter >= "M"))
        
      Console.WriteLine(output)                                     
   End Sub
   
   Private Function GetAlphabet(upper As Boolean) As List(Of String)
      Dim alphabet As New List(Of String)
      Dim charValue As Integer = CInt(IIf(upper, 65, 97))
      For ctr As Integer = 0 To 25
         alphabet.Add(ChrW(charValue + ctr).ToString())
      Next
      Return alphabet 
   End Function
End Module
' The example displays the following output:
'       MNOPQRSTUVWXYZ

Concat(String, String) Concat(String, String) Concat(String, String) Concat(String, String)

Concatena duas instâncias especificadas de String.Concatenates two specified instances of String.

public:
 static System::String ^ Concat(System::String ^ str0, System::String ^ str1);
public static string Concat (string str0, string str1);
static member Concat : string * string -> string
Public Shared Function Concat (str0 As String, str1 As String) As String

Parâmetros

str0
String String String String

A primeira sequência de caracteres a ser concatenada.The first string to concatenate.

str1
String String String String

A segunda sequência de caracteres a ser concatenada.The second string to concatenate.

Retornos

A concatenação de str0 e str1.The concatenation of str0 and str1.

Exemplos

O exemplo a seguir concatena o nome, o meio e o sobrenome de uma pessoa.The following example concatenates a person's first, middle, and last name.

using namespace System;
int main()
{
   
   // we want to simply quickly add this person's name together
   String^ fName = "Simon";
   String^ mName = "Jake";
   String^ lName = "Harrows";
   
   // because we want a name to appear with a space in between each name, 
   // put a space on the front of the middle, and last name, allowing for
   // the fact that a space may already be there
   mName = String::Concat(  " ", mName->Trim() );
   lName = String::Concat(  " ", lName->Trim() );
   
   // this line simply concatenates the two strings
   Console::WriteLine( "Welcome to this page, '{0}'!", String::Concat( String::Concat( fName, mName ), lName ) );
}
// The example displays the following output:
//        Welcome to this page, 'Simon Jake Harrows'!
using System;

public class ConcatTest {
    public static void Main() {

        // we want to simply quickly add this person's name together
        string fName = "Simon";
        string mName = "Jake";
        string lName = "Harrows";

        // because we want a name to appear with a space in between each name, 
        // put a space on the front of the middle, and last name, allowing for
        // the fact that a space may already be there
        mName = " " + mName.Trim();
        lName = " " + lName.Trim();

        // this line simply concatenates the two strings
        Console.WriteLine("Welcome to this page, '{0}'!", string.Concat( string.Concat(fName, mName), lName ) );
    }
}
// The example displays the following output:
//        Welcome to this page, 'Simon Jake Harrows'!
Public Class ConcatTest
    Public Shared Sub Main()
        Dim fName As String = "Simon"
        Dim mName As String = "Jake"
        Dim lName As String = "Harrows"
        
        ' We want to simply quickly add this person's name together.
        ' Because we want a name to appear with a space in between each name, 
        ' we put a space on the front of the middle, and last name, allowing for
        ' the fact that a space may already be there.
        mName = " " + mName.Trim()
        lName = " " + lName.Trim()
        
        ' This line simply concatenates the two strings.
        Console.WriteLine("Welcome to this page, '{0}'!", _
                          String.Concat(String.Concat(fName, mName), lName))
    End Sub
End Class
' The example displays the following output:
'       Welcome to this page, 'Simon Jake Harrows'!

Comentários

O método concatena str0 e str1; ele não adiciona nenhum delimitador.The method concatenates str0 and str1; it does not add any delimiters.

Uma cadeia de caracteres Empty é usada no lugar de qualquer argumento nulo.An Empty string is used in place of any null argument.

Veja também

Concat<T>(IEnumerable<T>) Concat<T>(IEnumerable<T>) Concat<T>(IEnumerable<T>) Concat<T>(IEnumerable<T>)

Concatena os membros de uma implementação IEnumerable<T>.Concatenates the members of an IEnumerable<T> implementation.

public:
generic <typename T>
 static System::String ^ Concat(System::Collections::Generic::IEnumerable<T> ^ values);
[System.Runtime.InteropServices.ComVisible(false)]
public static string Concat<T> (System.Collections.Generic.IEnumerable<T> values);
static member Concat : seq<'T> -> string
Public Shared Function Concat(Of T) (values As IEnumerable(Of T)) As String

Parâmetros de tipo

T

O tipo dos membros de values.The type of the members of values.

Parâmetros

values
IEnumerable<T> IEnumerable<T> IEnumerable<T> IEnumerable<T>

Um objeto de coleção que implementa a interface do IEnumerable<T>.A collection object that implements the IEnumerable<T> interface.

Retornos

Os membros concatenados em values.The concatenated members in values.

Exceções

Exemplos

O exemplo a seguir define uma classe Animal muito simples que contém o nome de um animal e a ordem à qual ele pertence.The following example defines a very simple Animal class that contains the name of an animal and the order to which it belongs. Em seguida, ele List<T> define um objeto para conter um Animal número de objetos.It then defines a List<T> object to contain a number of Animal objects. O Enumerable.Where método de extensão é chamado para extrair Animal os objetos Order cuja propriedade é igual a "roedoras".The Enumerable.Where extension method is called to extract the Animal objects whose Order property equals "Rodent". O resultado é passado para o Concat<T>(IEnumerable<T>) método e exibido para o console.The result is passed to the Concat<T>(IEnumerable<T>) method and displayed to the console.

using System;
using System.Collections.Generic;
using System.Linq;

public class Animal
{
   public string Kind;
   public string Order;
   
   public Animal(string kind, string order)
   {
      this.Kind = kind;
      this.Order = order;
   }
   
   public override string ToString()
   {
      return this.Kind;
   }
}

public class Example
{
   public static void Main()
   {
      List<Animal> animals = new List<Animal>();
      animals.Add(new Animal("Squirrel", "Rodent"));
      animals.Add(new Animal("Gray Wolf", "Carnivora"));
      animals.Add(new Animal("Capybara", "Rodent"));
      string output = String.Concat(animals.Where( animal => 
                      (animal.Order == "Rodent")));
      Console.WriteLine(output);  
   }
}
// The example displays the following output:
//      SquirrelCapybara
Imports System.Collections.Generic

Public Class Animal
   Public Kind As String
   Public Order As String
   
   Public Sub New(kind As String, order As String)
      Me.Kind = kind
      Me.Order = order
   End Sub
   
   Public Overrides Function ToString() As String
      Return Me.Kind
   End Function
End Class

Module Example
   Public Sub Main()
      Dim animals As New List(Of Animal)
      animals.Add(New Animal("Squirrel", "Rodent"))
      animals.Add(New Animal("Gray Wolf", "Carnivora"))
      animals.Add(New Animal("Capybara", "Rodent")) 
      Dim output As String = String.Concat(animals.Where(Function(animal) _
                                           animal.Order = "Rodent"))
      Console.WriteLine(output)                                           
   End Sub
End Module
' The example displays the following output:
'      SquirrelCapybara

Comentários

O método concatena cada objeto no values; ele não adiciona nenhum delimitador.The method concatenates each object in values; it does not add any delimiters.

Uma cadeia de caracteres Empty é usada no lugar de qualquer argumento nulo.An Empty string is used in place of any null argument.

Concat<T>(IEnumerable<T>)é um método de conveniência que permite concatenar cada elemento em uma IEnumerable<T> coleção sem primeiro converter os elementos em cadeias de caracteres.Concat<T>(IEnumerable<T>) is a convenience method that lets you concatenate each element in an IEnumerable<T> collection without first converting the elements to strings. Ele é particularmente útil com expressões de consulta LINQ (consulta integrada à linguagem), como ilustra o exemplo.It is particularly useful with Language-Integrated Query (LINQ) query expressions, as the example illustrates. A representação de cadeia de caracteres de cada IEnumerable<T> objeto na coleção é derivada chamando o método ToString desse objeto.The string representation of each object in the IEnumerable<T> collection is derived by calling that object's ToString method.

Aplica-se a