What am I doing wrong here? How can I execute my action?
var recurse = new Action<IItem, Int32>((item, depth) => { if (item.Items.Count() > 0) recurse(item, depth + 1); // red squiggly here // ... });
I'm getting a red squiggly when calling recurse
saying "method, delegate or event expected".
Update
I've accepted Homam's answer. I'd just like to add/share another syntax for the same... But which I find a bit easier on the eyes...
Action<IEnumerable<Item>> Recurse = null; Recurse = item => { if (item.Items != null) Recurse(item.Items); // ... };
A recursive lambda expression is the process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. Using a recursive algorithm, certain problems can be solved quite easily.
Just define the delegate Action
and assign null to it before calling it recursively.
Action<IItem, Int32> recurse = null;
Then
recurse = new Action<IItem, Int32>((item, depth ) => { if (item.Items.Count() > 0) recurse(item, depth + 1); // red squiggly here // ... });
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With