title: How does sorting a C# List based on a property work?
body: <p>So, I'm doing an assignment for my C# class and I have a list of objects. These objects have an 'int rand' field which is assigned a random number. I then wanted to re-sort the objects in the list based on this rand field. </p>
  
  <p>I found this article:
  <a href="http://www.developerfusion.com/code/5513/sorting-and-searching-using-c-lists/" rel="nofollow">http://www.developerfusion.com/code/5513/sorting-and-searching-using-c-lists/</a></p>
  
  <p>And it helped. I modified this line to fit my code: </p>
  
  <pre><code>people.Sort(delegate(Person p1, Person p2) { return p1.age.CompareTo(p2.age); });
  </code></pre>
  
  <p>And it does what I want. </p>
  
  <p>What I want to know is: how does it work? That looks very confusing to me. </p>