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);
}
}
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();
See more on this question at Stackoverflow