How to show the data of a List of Objects (collection) in C #?

1

They ask me to create a Race and an Athlete class, and show some data by console. In the Career Class I have to create a method that orders the contestants alphabetically. I tried to take the first and last, and it's all good. My problem is now:

public void ordenarPorNombre()
    {
        this.Competidores.OrderBy(x => x.getNombre()).Last().DatosAtleta();
    }

There I'm trying to get the last one, and it works, but I need you to show all in alphabetical order ... I guess I should just take the Last () and put another word that does, but I do not know what it is ...

Thanks in advance.

    
asked by PAWER20 30.04.2018 в 08:24
source

1 answer

2

Simply use Linq to order and then do a foreach:

public void ordenarPorNombre()
{
     this.Competidores.OrderByDescending(x => x.Nombre).ToList().ForEach(x=>x.DatosAtleta());
}
    
answered by 30.04.2018 в 10:58