C# String Concat Method

In c#, the string Concat method is used to concatenate or append one string to the end of another string and return a new string.

 

Following is the pictorial representation of appending two strings using the Concat() method in the c# programming language.

 

C# String Concat Method Representation Diagram

 

If you observe the above diagram, we are concatenating two strings,”Suresh” and “Dasari” by using the Concat method and returning a new string like “SureshDasari”.

C# String Concat Method Syntax

Following is the syntax of defining a Concat method to append one or more strings in the c# programming language.

 

public string Concat(string string1, string string2)

If you observe syntax, the Concat method will append multiple strings and return them as a new string.

C# String Concat Method Example

Following is the example of using the Concat() method to append or concatenate one or more strings and return it as a new string in the c# programming language.

 

using System;

namespace Tutlane
{
    class Program
    {
       static void Main(string[] args)
       {
          string msg1 = "Welcome to";
          string msg2 = " " + "tutlane";
          Console.WriteLine("Message: {0}", string.Concat(msg1, msg2));

          string name1 = "Suresh";
          string name2 = ", " + "Rohini";
          string name3 = ", " + "Trishika";
          Console.WriteLine("Users: {0}", string.Concat(string.Concat(name1, name2), name3));

          Console.WriteLine("\nPress Enter Key to Exit..");
          Console.ReadLine();
       }
    }
}

If you observe the above example, we used a Concat() method to append multiple strings and return them as a new string.

 

When you execute the above c# program, you will get the result below.

 

C# Concat Method Example Result

 

This is how you can use Concat() method to append or concatenate one or more strings into one string in the c# programming language.