In C#, concatenating strings can be done with the Concat()
method of the String
class.
In other cases, you can use the +
operator. This method returns a string which is the concatenation of the first and second strings.
string.Concat(stringA, stringB)
stringA
: This is the first string that you want to concatenate.
stringB
: This is the second string that you want to concatenate with the first string.
The value returned is a string that is the concatenation of stringA
and stringB
.
In the code snippet below, we have implemented the example illustrated in figure above. First, we defined and initialized the two strings Edpr
and esso
. Then with the help of Concat()
method, we concatenated the two strings.
using System; // create Concat class class Concat { // The main method static void Main() { // define and initialize strings string stringA = "Edpr"; string stringB = "esso"; // Concatenate strings string concatString = string.Concat(stringA, stringB); // print the concatenation System.Console.WriteLine(concatString); } }
RELATED TAGS
CONTRIBUTOR
View all Courses