+ 3

List sort question

I'm just learning lists in cs and put some code up (RacerListSort). I was wondering how best to take the list and sort it by "racetotal" in descending order then writing it out by racetotal + name. https://code.sololearn.com/cckL0V95e2ai/?ref=app

27th Jan 2018, 5:01 PM
Robyn Minter
Robyn Minter - avatar
2 Respuestas
27th Jan 2018, 10:16 PM
mustafacqn can
mustafacqn can - avatar
+ 1
Notice that your list is racers and the type of list is Racers. This is confusing and will create bugs in the long run. An object is always singular. So I made the class Racer And the list can be Racers (something containing more objects of type Racer) My personal preference is to add the word list to it so I made it racerslist You can do it using list.sort but then you have to implement the IComparable interface It is easier using LINQ or Lambda https://www.dotnetperls.com/sort-list http://www.java2s.com/Tutorial/CSharp/0450__LINQ/ListSortWithLambdaExpression.htm http://www.c-sharpcorner.com/UploadFile/afenster/lambda-expressions-are-wonderful/ https://code.sololearn.com/cvwBz1skip9a
27th Jan 2018, 10:46 PM
sneeze
sneeze - avatar