I was looking for a sufficient answer for quite some time but didn't have any luck.
As the title suggest, I am trying to read CSV data to the list. Basically I have a class called Person:
public string Name { get; set; }
public string Surname { get; set; }
public DateTime DateOfBirth { get; set; }
I am trying to read it from the CSV to the List. I'm not sure how to do that in terms of the rows so that it will match the name, surname, dob
The CSV file looks like that:
Name Surname Date Of Birth
Angela Blah 24/01/1990
In short, I want the 'Angela' details to be inserted in the List of Person object.
Any help would be appreciated. Thanks.
EDIT:
I did tried few things:
Create a constuctor in my Person class public Person(string line) { var split = line.Split(',');
Name = split[0];
Surname = split[1];
DateOfBirth = split[2];
}
Then wanted to use it like that:
var people = File.ReadLines("../people.csv").Select(line => new
Person(line)).ToList();
But of course it is empty because I am creating a new person. This is closest of what I could think of...is it the right direction for an answer or is it completely wrong?