Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue sorting with LINQ

Status
Not open for further replies.

sirnose1

Programmer
Nov 1, 2005
133
US
I have a delimited text file:

Steve,12,33
Tim,34,28
Mark,22,37
Tom,21,30
Cliff,13,33
Vini,17,28
Matt,10,28
Ben,9,29
Brandon,15,14

I need to sort this in ascending order by the second column. It works except I get this:

Matt 10 28
Steve 12 33
Cliff 13 33
Brandon 15 14
Vini 17 28
Tom 21 30
Mark 22 37
Tim 34 28
Ben 9 29

If I put a 0 in front of the 9 it will sort, properly. If not as you can see, it goes to the bottom of the list. Can't figure out why. Here is the code:


private void btnResults_Click(object sender, EventArgs e)
{
try
{
string strFileName = this.txtPath.Text;
var qry = from line in File.ReadAllLines("C:\\Users\\Bomac\\Desktop\\TestAge.txt")
let runner = line.Split(',')
orderby runner[1] ascending
select new Runner()
{
Name = runner[0],
Time = runner[1],
Age = runner[2]
};


foreach (var item in qry)
{
this.txtOutPut.AppendText((item.Name) + " " + (item.Time) + " " + (item.Age) + Environment.NewLine);
}

}
catch
{

}
finally
{

}

}

Any help would be greatly appreciated.



 
convert the value from a string to a number and then sort.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top