Skip to content

Instantly share code, notes, and snippets.

@niko86
Last active August 23, 2021 16:04
Show Gist options
  • Save niko86/ba2c4f2e8b6f8bac4003b83a386ac8ae to your computer and use it in GitHub Desktop.
Save niko86/ba2c4f2e8b6f8bac4003b83a386ac8ae to your computer and use it in GitHub Desktop.
void Main()
{
string filePath = @"example.csv";
SylvanCsv(filePath);
}
List<string> SylvanCsv(string filePath)
{
StreamReader sr = new(filePath);
List<string> listy = new();
var options = new CsvDataReaderOptions
{
HasHeaders = false,
ResultSetMode = ResultSetMode.SingleResult,
};
using var csv = CsvDataReader.Create(sr, options);
while (csv.Read())
{
"====== First Row ======".Dump();
string[] rowValues = new string[csv.RowFieldCount];
csv.GetValues(rowValues);
"-- Row Field Count For Loop Start".Dump();
for (int i = 0; i < csv.RowFieldCount; i++)
{
csv.GetString(i).Dump();
}
"-- Row Field Count For Loop End".Dump();
"-- Field Count For Loop Start".Dump();
for (int i = 0; i < csv.FieldCount; i++)
{
csv.GetString(i).Dump();
}
"-- Field Count For Loop End".Dump();
"====== Second Row ======".Dump();
csv.Read();
string[] rowValues2 = new string[csv.RowFieldCount];
csv.GetValues(rowValues2);
"-- Row Field Count For Loop Start".Dump();
for (int i = 0; i < csv.RowFieldCount; i++)
{
csv.GetString(i).Dump();
}
"-- Row Field Count For Loop End".Dump();
"-- Field Count For Loop Start".Dump();
for (int i = 0; i < csv.FieldCount; i++)
{
csv.GetString(i).Dump();
}
"-- Field Count For Loop End".Dump();
break;
}
return listy;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment