C# program to concatenate the two strings using a predefined method

Here, we are going to learn how to concatenate the two strings using a predefined method in C#?
Submitted by Nidhi, on October 12, 2020

Here, we will read two strings, then concatenate both strings and assigned to another string.


The source code to concatenate the two strings using a predefined method is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to concatenate two strings 
//using the predefined method.

using System;

class Demo
    static void Main()
        string str1 = "";
        string str2 = "";
        string str3 = "";

        Console.Write("Enter string1: ");
        str1 = Console.ReadLine();

        Console.Write("Enter string2: ");
        str2 = Console.ReadLine();

        str3=String.Concat(str1, str2);
        Console.WriteLine("Concatenated string is: {0}",str3);


Enter string1: Include
Enter string2: Help
Concatenated string is: IncludeHelp
Press any key to continue . . . 


Here, we created a class Demo that contains the Main() method, The Main() method is the entry point for the program, here we created three strings str1, str2, and str3. Then read the value of str1 and str2. After that concatenated the string str1 with str2 and assign the result into str3 using Concat() method of string class. Then we printed the result on the console screen.

C# Basic Programs »


Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.