How can I sort array of strings ascending in c#, I want use something like std::sort in C++:
std::sort(population.begin(), population.end())
I need to sort list of objects. The objects in list are instances of Genome class. I overloaded operator < and operator > in that class.
class Genome
{
public List<double> weights;
public double fitness;
public Genome()
{
fitness = 0.0;
weights = new List<double>();
}
public Genome(List<double> weights, double fitness) {
this.weights = weights;
this.fitness = fitness;
}
public static bool operator <(Genome lhs, Genome rhs)
{
return (lhs.fitness < rhs.fitness);
}
public static bool operator >(Genome lhs, Genome rhs) {
return (lhs.fitness > rhs.fitness);
}
}
This is how the population is declared:
List<Genome> population = new List<Genome>();
How can I sort this array? Can the operator overloaded operator be used < like in C++?