J'ai une collection IEnumerable<IEnumerable<T>>
que je veux convertir en une collection de dimension unique. Est-il possible d'y parvenir avec une méthode d'extension générique? En ce moment je fais ceci pour l'accomplir.Comment convertir un IEnumerable <IEnumerable <T>> en IEnumerable <T>
List<string> filteredCombinations = new List<string>();
//For each collection in the combinated results collection
foreach (var combinatedValues in combinatedResults)
{
List<string> subCombinations = new List<string>();
//For each value in the combination collection
foreach (var value in combinatedValues)
{
if (value > 0)
{
subCombinations.Add(value.ToString());
}
}
if (subCombinations.Count > 0)
{
filteredCombinations.Add(String.Join(",",subCombinations.ToArray()));
}
}
S'il n'est pas possible d'obtenir une solution générique, comment puis-je l'optimiser de façon élégante?
la question dans le titre réponse ici: http: // stackoverflow. com/questions/1590723/flatten-list-in-linq –