Writing data into CSV file in C#

后端 未结 15 1325
清酒与你
清酒与你 2020-11-22 17:15

I am trying to write into a csv file row by row using C# language. Here is my function

string first = reader[0].ToString();
string second=image.         


        
15条回答
  •  情话喂你
    2020-11-22 17:37

    Instead of calling every time AppendAllText() you could think about opening the file once and then write the whole content once:

    var file = @"C:\myOutput.csv";
    
    using (var stream = File.CreateText(file))
    {
        for (int i = 0; i < reader.Count(); i++)
        {
            string first = reader[i].ToString();
            string second = image.ToString();
            string csvRow = string.Format("{0},{1}", first, second);
    
            stream.WriteLine(csvRow);
        }
    }
    

提交回复
热议问题