Concatenate strings in C#

In this article we will discuss how to concatenate the two strings in C#.
  • 5184

Add two strings in C#

The Concat method of the string class concatenates one or more strings and objects and a combination of all.

The following code snippet shows different forms of sting and object concatenation.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int number = -123;
            bool b = false;
            Object numberObject = number;
            object boolObject = b;
            string author = "Mahesh Chand";
            Object[] objs = new Object[] { 555, 444, 999 };
            Console.WriteLine("Concatenate 1: {0}", String.Concat(numberObject));
            Console.WriteLine("Concatenate multiple: {0}", String.Concat(numberObject, boolObject, author));
            Console.WriteLine("Concatenate an array: {0}", String.Concat(objs));
            Console.ReadLine();
       }
    }
}


Further Readings
 
You may also want to read these related articles.

Ask Your Question 

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

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.