Array To Csv File - CSharp System

CSharp examples for System:Array Element

Description

Array To Csv File

Demo Code


using System.Linq;
using System.IO;/*w w w  .jav  a 2 s . co m*/
using System;

public class Main{
        public static void ToCsvFile<T>(this T[,] array, string filename)
        {
            var enumerator = array.Cast<T>().Select((s, i) => 
                (i + 1) % array.GetLength(0) == 0 
                    ? string.Concat(s, Environment.NewLine) 
                    : string.Concat(s, ","));

            var result = string.Join(string.Empty, enumerator.ToArray<string>());
            File.WriteAllText(filename, result);
        }
}

Related Tutorials