String Join C# | C# join string - c# - c# tutorial - c# net



C# Join String

C# Join String - c# examples - c# programs

What is C# join string ?

  • The join string() method combines many strings into one. The join string receives two arguments, such as:
    • An array of IEnumerable and
    • A separator string.
  • It places the separator between every element of the collection in the returned string.
 C#  join string

C# join string

Syntax:

string str = String.Join("string name")

C# Sample Code - C# Examples:

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

namespace wikitechy_join_string
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strjoin = new string[]{"Welcome to wikitechy 
            web site","www.wikitechy.com",
            "This is string join Method"};
     
            string str = String.Join("\n", strjoin);
   
            Console.WriteLine(str);

            Console.ReadLine();
        }
    } 
}

Code Explanation:

 c sharp string join list
  1. In this example we combine string elements from an array into a new, single string (string[] strjoin = new string[]) with dividing 3 characters (Welcome to wikitechy web site","www.wikitechy.com","This is string join Method"). This example will produce the output with separating commas.
  2. Here we use the string.Join method to combine a List of strings into one string.
  3. It Writes the string representation of the specified str object, followed by the current line terminator, to the standard output stream using the specified format information.

Sample C# examples - Output :

 c sharp string join lists
  1. Here in this output we display "welcome to wikitechy website" which specifies to new string array with first elements.
  2. In this output we display www.wikitechy.com which specifies to new string array with second elements.
  3. In this output we display "This is string join Method" which specifies to new string array with third elements.

Related Searches to String Join C# | C# join string