Addition and Concatenation in C#


To add and concatenate strings in C#, use the string. Concat method. The plus operator can also be used for the same purpose of concatenation.

Plus Operator

string str2 = "Hanks" + str1;

Example

Let us see an example of + operator to concatenate strings −

Live Demo

using System;

class Program {
   static void Main() {
      string str1 = "Tom";

      // concatenation
      string str2 = "Hanks" + str1;

      Console.WriteLine(str2);
   }
}

Output

HanksTom

String.concat

string str2 = string.Concat("Hanks", str1);

Example

Let us see an example of string.concat to concatenate strings in C# −

Live Demo

using System;

class Program {
   static void Main() {
      string str1 = "Tom";

      // concatenation
      string str2 = string.Concat("Hanks", str1);

      Console.WriteLine(str2);
   }
}

Output

HanksTom

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 19-Jun-2020

222 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements