c# - List sorting by multiple parameters -


i have .csv following headers , example line file.

agentid,profile,avatar,in_time,out_time,in_location,out_location,target_speed(m/s),distance_traveled(m),congested_duration(s),total_duration(s),los_a_duration(s),los_b_duration(s),los_c_duration(s),los_d_duration(s),los_e_duration(s),los_f_duration(s) 2177,defaultprofile,darkgreen_lowpoly,08:00:00,08:00:53,east12subwayportalactor,ewconcourseportalactor,1.39653,60.2243,5.4,52.8,26.4,23,3.4,0,0,0 

i need sort .csv 4th column (in_time) increasing time ( 08:00:00, 08:00:01) , 6th (in_location) alphabetical direction (e.g. east, north, etc).

so far code looks this:

list<string> list = new list<string>(); using (streamreader reader = new streamreader("journeytimes.csv")) {     string line;     while ((line = reader.readline()) != null)     {         line.split(',');         list.add(line);     } 

i read in .csv , split using comma (there no other commas not concern). add each line list. issue how sort list on 2 parameters , headers of .csv.

i have been looking day @ this, relatively new programming, first program apologize lack of knowledge.

you can use linq orderby/thenby:

e.g.

listofobjects.orderby (c => c.lastname).thenby (c => c.firstname) 

but first off, should map csv line object. map csv line object can predefine type or create dynamically

from line in file.readlines(filename).skip(1) //header let columns = line.split(',') //really basic csv parsing, consider removing empty entries , supporting quotes select new {   agentid = columns[0],   profile = int.parse(columns[1]),   avatar = float.parse(columns[2])   //other properties } 

and aware many other linq methods, these 2 use deferred execution


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -