I am using this CSV reader in attempt to print out Name, lastname and SSN from my CSV file:
static void Main(string[] args)
{
var query = File.ReadLines(@"C:\CSV\ToAdd.csv")
.SelectMany(line => line.Split(';'))
.Where(csvLine => !String.IsNullOrWhiteSpace(csvLine))
.Select(csvLine => new { data = csvLine.Split(',') })
.Select(s => new
{
Name = s.data[0],
Lastname = s.data[1],
SSN = s.data[2]
});
foreach (var item in query)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
So far I have had a bit of success, but the problem is it keeps printing out the name of the column as well:
{ Name = Hej, Lastname = Hoj, SSN= 950505-1432 }
{ Name = Huj, Lastname = Hij, SSN= 940304-1332 }
which part of the code is making it so it gets printed out like that instead of printing out only the records?