I have an IEnumerable collection, which is hierarchical in that one element contains several within it. Thus, if I do a count, I may get 7-8 as the return int, when really there could be 500 items (as they’re nested).
How can I flatten this collection into a collection with all the elements and no nesting?
Thanks
Assuming that
smallEnumerableis the collection with 7-8 items, each one of which has a propertySubItemswhich is itself an enumerable of items of the same type, then you flatten like this:If each one of the
SubItemscan haveSubItemsitself, then some recursion is in order: