potrebbe non essere formulati perfettamente ragione, ma qui è quello che ho ed ecco il risultato che voglio raggiungere:utilizzando LINQ, come GroupBy contro gli oggetti in un elenco all'interno dell'oggetto di destinazione
class Cake
{
public List<string> Ingrediants {get;set;}
public DateTime Baked {get;set;}
public string CakeName {get;set;}
}
List<Cake> cakes= new List<Cake>();
cakes.Add(new Cake() {CakeName = "Cake1", Ingrediants = new List<string>() {"Sugar", "Chocolate"}});
cakes.Add(new Cake() {CakeName = "Cake2", Ingrediants = new List<string>() {"Sugar", "Butter"}});
cakes.Add(new Cake() {CakeName = "Cake3", Ingrediants = new List<string>() {"Stevia", "Butter"}});
Vorrei gruppo le torte di ingrediant. Quindi mi piacerebbe finire con questo:
- Sugar
Cake1
Cake2
- Stevia
Cake3
- Chocolate
Cake1
- Butter
Cake2
Cake3
Grazie in anticipo!
Cosa vuoi, GroupBy o OrderBy? Inoltre non è chiaro come siano ordinati i dolci. –
Voglio raggrupparli usando GroupBy su ingrediant. L'ordine della torta non è importante – Tom