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.

  1. create class represent data. lets call person person have 3 properties id(int), gender(string), name(string)
  2. create list<person> listofperson = new list<person>();
  3. read file line line using loop -> check file.readlines method
  4. create new instance of class in loop person person = new person();
  5. take line file, call string.split(',');
  6. set person properties string[] create splitting p.id = arr[0] , on
  7. add person class list<person>

i answer text should try , learn how in future !


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -