How to Concatenate more than one Strings in C#

In this article we are discussing about how to concatenate more than two Strings in C#.
  • 2751

In this article we are discussing about how to concatenate more than one String in C# without using Concat() method String Class. For this we have to use + or += operator to concatenate more than one Strings in C#. But if we are concatenating large number of strings then we for it we need to use StringBuilder Class to improve the efficiency of our program but in case of limited number of strings we can use + or += operator to concatenate more than one strings in C#.

Lets have a look on the following example:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ConsoleApplication17

{

    class Program

    {

        static void Main(string[] args)

        {

            string yourName = Console.ReadLine();

            string d = DateTime.Today.ToShortDateString();

 

            // Use the + and += operators for one-time concatenations.

            string s = "Hiii " + yourName + ". Today is " + d + ".";

            System.Console.WriteLine(s);

 

            s += " Have a nice day?";

            System.Console.WriteLine(s);

 

            // Keep the console window open in debug mode.

            Console.WriteLine("Press any key to exit.");

            Console.ReadLine();

        }

    }

}

Output:

Image26.jpg

Ask Your Question

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.