This sample program will help you to concatenate two given string. We have demonstrated two methods to concatenate.
string.Concat(strInput1, "-", strInput2);
is a efficient method to concatenate two string , you can use any one of these methods as per your convenience.
Source Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace MyFirstConsoleApp
{
class Program
{
static void Main(string[] args)
{
string strResults = "";
Console.WriteLine("Please enter first string:");
string strInput1 = Console.ReadLine();
Console.WriteLine("Please enter second string:");
string strInput2 = Console.ReadLine();
Console.WriteLine("you have entered string 1: " + strInput1 + " and string 2: " + strInput2);
Console.WriteLine();
//method 1
strResults = strInput1 + "-"+strInput2;
Console.WriteLine("Output of concatination: " + strResults);
//method 1
strResults = string.Concat(strInput1, "-", strInput2);
Console.WriteLine("Output of concatination: " + strResults);
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
}
}
0 comments:
Post a Comment