.Concat()
Anonymous contributor
Published Nov 15, 2024
Contribute to Docs
The .Concat()
method combines strings by appending one string to the end of another. This method is similar in function to using the +
or +=
operator to concatenate strings, though the compiler handles those operators differently for optimization in certain scenarios.
Syntax
string.Concat(string1, string2, ...)
string1, string2, ...
: The strings that will be concatenated together.
Example
The following example uses the .Concat()
method to combine three strings:
using System;public class ConcatMethod{public static void Main(){string firstString = "Hello";string secondString = "World!";string fullSentence = string.Concat(firstString, " ", secondString);Console.WriteLine(fullSentence);}}
This results in the following output:
Hello World!
Codebyte Example
The below codebyte example demonstrates how .Concat()
can be used with a foreach
loop to iterate through a list and output multiple concatenated strings:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C# on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn C#
Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.Beginner Friendly23 hours