-1

我正在尝试确认该程序是否正常工作,有没有办法将这些数组的值输出到控制台?

using System;
using Microsoft.VisualBasic.FileIO;

class ReadingCSV
{
    public static void Main()
    {
        string column1;
        string column2;
        var path = @"I:\Mfg\Process Engineering\User mfg\Tyler Gallop\CSV Reader\excel_test.csv";
        using (TextFieldParser csvReader = new TextFieldParser(path))
        {
            csvReader.CommentTokens = new string[] { "#" };
            csvReader.SetDelimiters(new string[] { "," });
            csvReader.HasFieldsEnclosedInQuotes = true;

            // Skip the row with the column names
            csvReader.ReadLine();

            while (!csvReader.EndOfData)
            {
                // Read current line fields, pointer moves to the next line.
                string[] fields = csvReader.ReadFields();
                column1 = fields[0];
                column2 = fields[1];
            }
        }
    }
}
4

2 回答 2

0

尝试 console.writeline 或 system.diagnositics.trace.traceinformation

于 2021-03-17T19:15:54.093 回答
0

您可以使用string.Join连接返回的字符串数组,并使用 .Join 将它们打印到控制台WriteLine()

System.Console.WriteLine(string.Join(',', fields);

如果你想单独打印数组的项目,那么只需循环调用它们WriteLine......下面的一些变体:

Console.WriteLine("Here's some fields in a line");
foreach(var field in fields)
    Console.WriteLine(field);
于 2021-03-18T22:06:35.183 回答