I have a list-generic that has a property (class type). I need a sort method for Z parameters (TrainingSet):
public override List<TrainingSet> CalculatedDistancesArray
(List<TrainigSet> ts, double x, double y, int k)
{
for (int i =0; i < 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<TrainingSet> sortedlist = new List<TrainingSet>();
for (int i = 0; i < 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; }
}