Pregunta

I have the following structures in c#:

public class Circus {
    int Id;
    public List<Performers> Performers = new List<Performers>();
}

public class Performer {
    int Id;
    public List<Talents> Talents = new List<Talents>();
}

public class Talent {
    public int Id;
    public string Name;
    public int skill;
}

How would I order Performers by skill (where Talent.Id == 1)? That is to say, I need to order a List by a property of it's child List. I've tried various attempts and searches but nothing as of yet will order the list in this way. Thank you in advance for any help.

¿Fue útil?

Solución

LINQ solution:

var ordered = source.OrderBy(p => p.Talents.First(t => t.Id == 1).Skill).ToList();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top