Sort List by decreasing values

Asked

Viewed 4,935 times

3

I have an object Chromosome:

public List<int> Rotas { get; set; }
public int ValorFitness { get; set; } 

And I also have a list of that object List<Cromossomo>.

I’d like to sort this list by property Valorfitness, in descending order.

I’m using C#, Windowsform, Dotnet 4.5.1

2 answers

3


You can use the .OrderByDescending

Example:

var listaOrdenada = cromossomos.OrderByDescending(e => e.ValorFitness);

3

Using Language Integrated Query () and Lambda.

An example:

List<Cromossomo> comossomosOrdenados = cromossomos.OrderByDescending(c => c.ValorFitness);

Another example:

List<Cromossomo> comossomosOrdenados = (from c in cromossomos
        orderby c.ValorFitness descending
        select c).ToList();

At this link have some examples of Linq.

  • This bass example is Lambda? Wouldn’t it be Linq? I think the examples are inverse D:

  • 1

    @Filipeoliveira I’ll be adjusting, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.