我想确认这个程序是否正常工作,有没有办法将这些数组的值输出到控制台?
I am trying to confirm that this program is working properly, is there a way to output the values of these arrays to the console?
我正在尝试确认这个程序是否正常工作,有没有办法将这些数组的值输出到控制台?
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];
}
}
}
}
尝试console.writeline或system.diagnositics.trace.traceinformation
您可以连接使用 string.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);
我正在尝试确认这个程序是否正常工作,有没有办法将这些数组的值输出到控制台?
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];
}
}
}
}
尝试console.writeline或system.diagnositics.trace.traceinformation
您可以连接使用 string.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);