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 a two strings using Concat() method in c# programming language.

 

C# String Concat Method Representation Diagram

 

If you observe above diagram, we are concatenating two strings ”Suresh” and “Dasari” by using Concat method and return 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 c# programming language.

 

public string Concat(string string1, string string2)

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

C# String Concat Method Example

Following is the example of using Concat() method to append or concatenate one or more strings and return it as new string in 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 above example, we used a Concat() method to append multiple strings and returning it as a new string.

 

When we execute above c# program, we will get the result like as shown below.

 

C# Concat Method Example Result

 

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