Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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 −
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# −
using System;
class Program {
static void Main() {
string str1 = "Tom";
// concatenation
string str2 = string.Concat("Hanks", str1);
Console.WriteLine(str2);
}
}
Output
HanksTom
Advertisements
