How to concatenate two strings in C#?

CsharpProgrammingServer Side Programming

To concatenate two strings, use the String.Concat method.

Let’s say you want to concatenate two strings in C#, str1 and str2, then add it as arguments in the Concat method −

string str3 = string.Concat(str1, str2);

Example

The following is the example −

 Live Demo

using System;

class Program {
   static void Main() {

      string str1 = "Brad";
      string str2 = "Pitt";

      // Concat strings
      string str3 = string.Concat(str1, str2);
      Console.WriteLine(str3);
   }
}

Output

BradPitt
raja
Published on 07-Aug-2018 13:27:38
Advertisements