title: How to sort list type generic if more than one property?
body: <p>I have a list-generic that has a property (class type). I need a sort method for Z parameters (TrainingSet):</p>
  
  <pre><code>public override List&lt;TrainingSet&gt; CalculatedDistancesArray
      (List&lt;TrainigSet&gt; ts, double x, double y, int k)
  {
      for (int i =0; i &lt; ts.Count; i++)
      {
          ts[i].Z = (Math.Sqrt(Math.Pow((ts[i].X - x), 2) 
                    + Math.Pow((ts[i].Y - y), 2)));
      }
      // I want to sort according to Z
      ts.Sort(); //Failed to compare two elements in the array.
      List&lt;TrainingSet&gt; sortedlist = new List&lt;TrainingSet&gt;();
      for (int i = 0; i &lt; k; i++)
      {
          sortedlist.Add(ts[i]);
      }
      return ts;
  }
  
  public class TrainigSet
  {
      public double X { get; set; }
      public double Y { get; set; }
      public double Z { get; set; }
      public string Risk { get; set; }
  }
  </code></pre>