title: C# - Windows Store App - How to sort a List<JsonObject>?
body: <p>My App has a <code>List&lt;T&gt;</code> of <code>JsonObject</code>'s and I want to be able to sort them.</p>
  
  <p>My <code>JsonObject</code>'s are derived from something similar to</p>
  
  <pre><code>{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 25,
  "height_cm": 167.64,
  "address": {
      "streetAddress": "21 2nd Street",
      "city": "New York",
      "state": "NY",
      "postalCode": "10021-3100"
  },
  "phoneNumbers": [
      { "type": "home", "number": "212 555-1234" },
      { "type": "fax",  "number": "646 555-4567" }
  ]
  }
  </code></pre>
  
  <p>I'm fairly new to C# and .NET and started writing a sort algorithm</p>
  
  <pre><code>        public  List&lt;JsonObject&gt; SortAgeAsc(List&lt;JsonObject&gt; data)
          {
              List&lt;JsonObject&gt; sorted = new List&lt;JsonObject&gt;();
              // Iterate through each object and sort into age order
              foreach(JsonObject jo in data)
              {
                  bool added = false;
                  for(int i = 0; i &lt; sorted.Count; i++)
                  {
                      // If our data object has a lower age then the current sorted object, add it in its place.
                      if(jo.GetNamedNumber("age") &lt;= sorted.ElementAt(i).GetNamedNumber("age"))
                      {
                          sorted.Insert(i, jo);
                          added = true;
                          break;
                      }
                  }
                  // If we are yet to add it, it must be the oldest so far. 
                  if (!added)
                      sorted.Add(jo);
              }
              return sorted;
          }
  </code></pre>
  
  <p>NOTE: Please don't comment about whether or not this is an efficient sort or not, as that's beyond the scope of this question.</p>
  
  <p>I then started reading about <code>List&lt;T&gt;.Sort()</code> and thought there must be way use that instead of writing the sort algorithm myself, as I would hope it was an efficient way of sorting.</p>
  
  <p>Most examples I came across used class properties to sort on. Is there a way I can sort my <code>List&lt;JsonObject&gt;</code>on a particular json key (like "age" in my example above)?  </p>