find and solve || findandsolve.com
Please wait.....

C# String Concat Method

String.Concat Method is used to concatenate one or more instances of one string to the end of another string. You concatenate strings by using the + operator.add two strings, two objects and one string and one object or more combination of these two. The Concat method adds strings (or objects) and returns a new string.

C# String Concat Method Syntax

In the given below  the syntax of defining a Concat method to append one or more strings in the c# language.

public string Concat(string firstString, string secondString)

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


C# String Concat Method Example


Example
    using System;   
    public class StringExample
    {
        public static void Main(string[] args)
        {
             string str = "First String Value";
             string str1 = "Second String Value";
             Console.WriteLine(string.Concat(str,str1));
        }
    }   
output
First String Value Second String Value

In the given above example, using the Concat() method to append or concatenate one or more strings and return it as a new string in the c#  as 'First String Value Second String Value'.


For more example

    using System;
    public class StringContactExample
    {
        public static void Main(string[] args)
        {
          string str = "Welcome to";
          string str1 = " " + "Find And Solve";
          Console.WriteLine("Message: {0}", string.Concat(str, str1));
          string string1 = "Sylvia";
          string string2 = ", " + "Devin";
          string string3 = ", " + "Atenika";
          Console.WriteLine("Name List: {0}", string.Concat(string.Concat(string1, string2), string3));
          Console.ReadLine();
        }
    }    

output
Message: Welcome to Find And Solve
Name List: Sylvia, Devin, Atenika