How do I create delimited value from an array?

Category: System, viewed: 1K time(s).

If you want to create a delimited string value out of an array you can use the string.Join() method. The Join method we use below accept two parameters. The delimiter character use to delimiting one value from the other which is the comma symbol and the source information to be delimited, which is the array.

The Join method will return a single string that concatenate all the values in the array delimited with the delimiter symbol.

using System;

namespace Kodecsharp.Example.System
{
    public class StringDelimitedCreate
    {
        public static void Main(string[] args)
        {
            string[] numbers = { "1", "1", "2", "3", "5", "8", "13" };

            //
            // Creating a delimited value of the numbers array and use
            // comma symbol as the delimiter.
            //
            string delimitedValue = string.Join(",", numbers);

            Console.WriteLine("Delimited Value: " + delimitedValue);
            Console.ReadLine();
        }
    }
}
Powered by Disqus