c# - Putting contents of a .txt file into a List in -
i have .txt file looks this:
1,bob,male //first row 2,jim,male //second row 3,mary,female //third row i want put these items generic list in c#, storing each column "id", "name", "gender" , treating each row different item of list.
how go doing this? have no idea start. i've looked @ i/o operations , understand how access file, don't know how create variable name each column , store each row new entry.
- create class represent data. lets call
personperson have 3 propertiesid(int),gender(string),name(string) - create
list<person> listofperson = new list<person>(); - read file line line using loop -> check
file.readlinesmethod - create new instance of class in loop
person person = new person(); - take line file, call
string.split(','); - set person properties
string[]create splittingp.id = arr[0], on - add person class
list<person>
i answer text should try , learn how in future !
Comments
Post a Comment