C# String join method

In this article we will discuss about how to use join method regarding string in C#.
  • 4430

The Join method is useful when you need to insert a separator (String) between each element of a string array, yielding a single concatenated string. For example, the following sample inserts a comma and space (", ") between each element of an array of strings.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; 

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            string name = "Mahesh Chand";
            string add = "is an author";
            string add2 = " and founder of C# Corner";
            string[] sentence = new String[] { name, add, add2 };
            string result = String.Join(", ", sentence);
            Console.WriteLine("Join Results: " + result);
            Console.ReadLine();
        }
    }
}


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

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.