I have a list class that has a Title (string) Rank (int) and a couple of other string elements. I’d like to be able to sort the list so that I can sort the whole bit by the rank.
For instance:
Title Rank Bla1 Bla2
---------------------------------------------------------
Whatever 0 Bla Blabety Bla
Something Else 4 Bla2 Double Bla
Howdy 1 Bla3 asdf
Last 2 Bla4 fdsa
Becomes:
Title Rank Bla1 Bla2
----------------------------------------------------------
Something Else 4 Bla2 Double Bla
Last 2 Bla4 fdsa
Howdy 1 Bla3 asdf
Whatever 0 Bla Blabety Bla
Here’s the class declaration:
public class Results
{
public string title { get; set; }
public int rank { get; set; }
public string term { get; set; }
public string studentComment { get; set; }
}
And the list declaration:
public List<Results> studentList = new List<Results>();
How would I take studentList and sort it by rank to get the results shown above?
Thanks in advance!
Lambda Expressions to the rescue!