add the results of all linq statements to one big enumeration

How can i do this code in one linq statement?

i.e. add the results of all linq statements to one big enumeration

List<Type> alltypes = new List<Type>();
var assemblies = AppDomain.CurrentDomain.GetAssemblies();

foreach (var assembly in assemblies) 
{
    foreach (var type in assembly.GetTypes()) 
    {
    alltypes.Add(type);
    }
}
Jon Skeet
people
quotationmark

It sounds like you want:

var allTypes = AppDomain.CurrentDomain.GetAssemblies()
                        .SelectMany(assembly => assembly.GetTypes())
                        .ToList();

Use SelectMany when one "input" item (an assembly in this case) is used as the source for multiple other items (types in this case).

If you want it in a query expression:

var allTypes = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
                from type in assembly.GetTypes()
                select type).ToList();

people

See more on this question at Stackoverflow