Q:

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

belongs to collection: C# Basic Programs | String programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

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);
    }
}

Output:

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

Explanation:

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 str1str2, 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.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | String programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to reverse a given string without using... >>
<< C# program to count the total number of digits in ...