MSDN Home > MSDN Library > .NET Development > .NET Framework SDK > .NET Framework > Reference > Class Library > System > String Class > Methods > Concat Method |
Concatenates the elements of a specified String array. [Visual Basic] Overloads Public Shared Function Concat( _ ByVal ParamArray values() As String _ ) As String [C#] public static string Concat( params string[] values ); [C++] public: static String* Concat( String* values __gc[] ); [JScript] public static function Concat( values : String[] ) : String; Parameters
Return ValueThe concatenated elements of values. Exceptions
RemarksAn Empty string is used in place of any null object in the array. ExampleThe following code example demonstrates the use of the Concat method with a String array. [Visual Basic] Imports System Public Class ConcatTest Public Shared Sub Main() Dim s As String() = {"hello ", "and ", "welcome ", "to ", "this ", "demo! "} ' make an array of strings. Note that we have included spaces ' 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 'Main End Class 'ConcatTest [C#] using System; public class ConcatTest { 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)); } } [C++] #using <mscorlib.dll> using namespace System; int main() { // make an array of strings. Note that we have included spaces String* s[] = { S"hello ", S"and ", S"welcome ", S"to ", S"this ", S"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)); } [JScript] import System; public class ConcatTest { public static function Main() : void { // make an array of strings. Note that we have included spaces var s : String [] = [ "hello ", "and ", "welcome ", "to ", "this ", "demo! "]; // put all the strings together Console.WriteLine(System.String.Concat(s)); // sort the strings, and put them together System.Array.Sort(s); Console.WriteLine(System.String.Concat(s)); } } ConcatTest.Main(); RequirementsPlatforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard See AlsoString Class | String Members | System Namespace | String.Concat Overload List | Join | String Members (Visual J# Syntax)Managed Extensions for C++ Programming |