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

Updated: October 2009

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(Object[]).

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

[CLSCompliantAttribute(false)]
public static string Concat(
	Object arg0,
	Object arg1,
	Object arg2,
	Object arg3
)

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.

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.

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.

using namespace System;

void main()
{
   int houseNumber = 172;
   String^ street = "Elm Street";
   String^ city = "Anywhere";
   String^ state = "NY";
   String^ zip = "60101";
   String^ sp = " ";
   String^ address = String::Concat(houseNumber, sp, street, "\n", city, ", " ,state, sp, zip);
   Console::WriteLine(address);
   Console::ReadLine();
}
// The example displays the following output: 
//      172 Elm Street 
//      Anywhere, NY 60101

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Date

History

Reason

October 2009

Added the Notes for Callers section and an example.

Information enhancement.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft