c# - read the txt file and sort it -


like title txt file

the grades 0~100

sample:

name,grades

name,grades

name,grades

and have sort grades

is way solve split them array sorting?

i have load file string

char[] spli = { ' ', ',', '\t' };         string line;         string[] sline;          streamreader file = new streamreader(textbox1.text,encoding.default);         line = file.readtoend();         sline = line.split(spli);         foreach (string item in sline)         {             listbox1.items.add(item);          } 

plz

when read data text file , parsing it, validation. never know data in file. see code.

class mylistuser     {         public string name;         public int  grades;     }  private list<mylistuser> readuserfile()         {             list<mylistuser> lstuser;             string[] smydata = file.readalllines("myfile.txt");             if (smydata != null)             {                 mylistuser otmp;                 string[] stmp;                 lstuser = new list<mylistuser>();                 (int = 0; < smydata.getlength(0); i++)                 {                     stmp = regex.split(smydata[i], ",");                     //need validation                     if (stmp != null && stmp.getlength(0) > 1)                     {                         otmp = new mylistuser();                         otmp.name = stmp[0];                         int.tryparse(stmp[1], out otmp.grades );                         lstuser.add(otmp);                     }                 }                 return lstuser.orderby(o => o.grades).tolist();             }             return null;         } 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -