Q:

C# Lambda expression with IComparer and Array.Sort (converting from Java to C#)

I'm trying to convert my lambda expression that uses the Comparator interface from Java to C#. I got the  following error:

Cannot convert lambda expression to type
  'System.Collections.IComparer' because it is not a delegate type.

I tried to switch to Comparison<T>, but it doesn't work with my Array.Sort methods: 
Array.Sort(Population, Population[0].Comparator);
Array.Sort(population, 0, population.Length, population[0].Comparator);

PregancyIndividual implements IGeneticIndividual interface.
public virtual IGeneticIndividual[] selectPopulation(IGeneticIndividual[] population)
    {
        IGeneticIndividual[] res = new IGeneticIndividual[population.Length];
        Array.Sort(population, 0, population.Length, population[0].Comparator);

Here is my Java code:
@Override
public Comparator getComparator() {
    Comparator<PregnancyIndividual> IndividualFitnessComparator
            = (PregnancyIndividual ind1, PregnancyIndividual ind2) -> {
                int res = 1;
                double fitness1 = ind1.getFitnessCalculator().calculateFitness(ind1);
                double fitness2 = ind2.getFitnessCalculator().calculateFitness(ind2);
                if (fitness1 > fitness2) {
                    return -1;
                }
                if (fitness1 == fitness2) {
                    return 0;
                }
                return res;
            };
    return IndividualFitnessComparator;
}

PregnancyIndividual implementing my own interface :
public class PregnancyIndividual implements IGeneticIndividual

I am now trying to implement my code for C#:
public virtual IComparer Comparator
    {
       get
        {
            //<PregnancyIndividual>
            IComparer IndividualFitnessComparator = (PregnancyIndividual ind1, PregnancyIndividual ind2) =>
            {
                int res = 1;
                double fitness1 = ind1.FitnessCalculator.calculateFitness(ind1);
                double fitness2 = ind2.FitnessCalculator.calculateFitness(ind2);
                if (fitness1 > fitness2)
                {
                    return -1;
                }
                if (fitness1 == fitness2)
                {
                    return 0;
                }

                return res;
            };

            return IndividualFitnessComparator;
        }
    }

A:

Change your PregnancyIndividual class to implement Icomparer and implement Compare as bellow:
    class PregnancyIndividual : IComparer
    {
        int IComparer.Compare(object a, object b)
        {
            PregnancyIndividual ind1 = (PregnancyIndividual)a;
            PregnancyIndividual ind2 = (PregnancyIndividual)b;
            int res = 1;
            double fitness1 = ind1.FitnessCalculator.calculateFitness(ind1);
            double fitness2 = ind2.FitnessCalculator.calculateFitness(ind2);
            if (fitness1 > fitness2)
            {
                return -1;
            }
            if (fitness1 == fitness2)
            {
                return 0;
            }

            return res;
        }    
    }

