- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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