/ Published in: C#
Credit: Tim Schmelter
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public static IEnumerable<T> Traverse<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> fnRecurse) { foreach (T item in source) { yield return item; IEnumerable<T> seqRecurse = fnRecurse(item); if (seqRecurse != null) { foreach (T itemRecurse in Traverse(seqRecurse, fnRecurse)) { yield return itemRecurse; } } } }
URL: http://stackoverflow.com/questions/12318372/linq-nested-list-contains