Tengo una colección IEnumerable<IEnumerable<T>>
que quiero convertir a una colección de una dimensión. ¿Es posible lograr esto con un método de extensión genérico? En este momento estoy haciendo esto para lograrlo.Cómo convertir un IEnumerable <IEnumerable <T>> a un 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()));
}
}
Si no es posible obtener una solución genérica, ¿cómo puedo optimizar este de una manera elegante de moda.
la pregunta del título es respondida aquí: http: // stackoverflow. com/questions/1590723/flatten-list-in-linq –