Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

string
concat
c#
communitycreator

How to use the String Concat() in C#

Theodore Kelechukwu Onyejiaku

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.

Concatenation of two strings with Concat() String Method

Syntax

string.Concat(stringA, stringB)

Parameters

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.

Return value

The value returned is a string that is the concatenation of stringA and stringB.

Code example

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

string
concat
c#
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku
RELATED COURSES

View all Courses

Keep Exploring